Git Product home page Git Product logo

dense-analysis / ale Goto Github PK

View Code? Open in Web Editor NEW
13.3K 91.0 1.4K 18.04 MB

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support

License: BSD 2-Clause "Simplified" License

Shell 1.98% Batchfile 0.06% Elixir 0.01% Python 1.05% Kotlin 0.01% Dockerfile 0.05% VHDL 0.01% Racket 0.02% Jsonnet 0.01% JavaScript 0.01% Vim Script 96.64% Lua 0.20%
linter vim syntax-checker vim-plugin vim-plugins language-server-protocol neovim-plugin languageclient autocomplete

ale's Introduction

Asynchronous Lint Engine

Vim Neovim CI AppVeyor Build Status Join the Dense Analysis Discord server

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

ALE (Asynchronous Lint Engine) is a plugin providing linting (syntax checking and semantic errors) in NeoVim 0.6.0+ and Vim 8.0+ while you edit your text files, and acts as a Vim Language Server Protocol client.

ale-demo.mp4

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.

ALE offers support for fixing code with command line tools in a non-blocking manner with the :ALEFix feature, supporting tools in many languages, like prettier, eslint, autopep8, and more.

ALE acts as a "language client" to support a variety of Language Server Protocol features, including:

  • Diagnostics (via Language Server Protocol linters)
  • Go To Definition (:ALEGoToDefinition)
  • Completion (Built in completion support, or with Deoplete)
  • Finding references (:ALEFindReferences)
  • Hover information (:ALEHover)
  • Symbol search (:ALESymbolSearch)

If you don't care about Language Server Protocol, ALE won't load any of the code for working with it unless needed. One of ALE's general missions is that you won't pay for the features that you don't use.

Help Wanted: If you would like to help maintain this plugin by managing the many issues and pull requests that are submitted, please send the author an email at [email protected].

If you enjoy this plugin, feel free to contribute or check out the author's other content at w0rp.com.

Why ALE?

ALE has been around for many years, and there are many ways to run asynchronous linting and fixing of code in Vim. ALE offers the following.

  • No dependencies for ALE itself
  • Lightweight plugin architecture (No JavaScript or Python required)
  • Low memory footprint
  • Runs virtually everywhere, including remote shells, and in git commit
  • Out of the box support for running particular linters and language servers
  • Near-zero configuration with custom code for better defaults
  • Highly customizable and well-documented (:help ale-options)
  • Breaking changes for the plugin are extremely rare
  • Support for older Vim and Neovim versions
  • Windows support
  • Well-integrated with other plugins

Supported Languages and Tools

ALE supports a wide variety of languages and tools. See the full list in the Supported Languages and Tools page.

Usage

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 behavior 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-integration-options for options specified to particular linters.

Fixing

ALE can fix files with the ALEFix command. Functions need to be configured either in each buffer with a b:ale_fixers, or globally with g:ale_fixers.

The recommended way to configure fixers is to define a List in an ftplugin file.

" In ~/.vim/ftplugin/javascript.vim, or somewhere similar.

" 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.

A * in place of the filetype will apply a List of fixers to all files which do not match some filetype in the Dictionary.

Note that using a plain List for g:ale_fixers is not supported.

" In ~/.vim/vimrc, or somewhere similar.
let g:ale_fixers = {
\   '*': ['remove_trailing_lines', 'trim_whitespace'],
\   'javascript': ['eslint'],
\}

If you want to automatically fix files when you save them, you need to turn a setting on in vimrc.

" Set this variable to 1 to fix files when you save them.
let g:ale_fix_on_save = 1

The :ALEFixSuggest command will suggest some supported tools for fixing code. Both g:ale_fixers and b:ale_fixers can also accept functions, including lambda functions, as fixers, for fixing files with custom tools.

See :help ale-fix for complete information on how to fix files with ALE.

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 from tsserver for TypeScript.

ALE integrates with Deoplete as a completion source, named 'ale'. You can configure Deoplete to only use ALE as the source of completion information, or mix it with other sources.

" Use ALE and also some plugin 'foobar' as completion sources for all code.
call deoplete#custom#option('sources', {
\ '_': ['ale', 'foobar'],
\})

ALE also offers its own automatic completion support, which does not require any other plugins, and can be enabled by changing a setting before ALE is loaded.

" Enable completion where available.
" This setting must be set before ALE is loaded.
"
" You should not turn this setting on if you wish to use ALE as a completion
" source for other completion plugins, like Deoplete.
let g:ale_completion_enabled = 1

ALE provides an omni-completion function you can use for triggering completion manually with <C-x><C-o>.

set omnifunc=ale#completion#OmniFunc

ALE supports automatic imports from external modules. This behavior is enabled by default and can be disabled by setting:

let g:ale_completion_autoimport = 0

Note that disabling auto import can result in missing completion items from some LSP servers (e.g. eclipselsp). See :help ale-completion for more information.

Go To Definition

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

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

Find References

ALE supports finding references for words under your cursor with the :ALEFindReferences command using any enabled Language Server Protocol linters and tsserver.

See :help ale-find-references for more information.

Hovering

ALE supports "hover" information for printing brief information about symbols at the cursor taken from Language Server Protocol linters and tsserver with the ALEHover command.

Truncated information will be displayed when the cursor rests on a symbol by default, as long as there are no problems on the same line.

The information can be displayed in a balloon tooltip in Vim or GVim by hovering your mouse over symbols. Mouse hovering is enabled by default in GVim, and needs to be configured for Vim 8.1+ in terminals.

See :help ale-hover for more information.

Symbol Search

ALE supports searching for workspace symbols via Language Server Protocol linters with the ALESymbolSearch command.

Search queries can be performed to find functions, types, and more which are similar to a given query string.

See :help ale-symbol-search for more information.

Refactoring: Rename, Actions

ALE supports renaming symbols in code such as variables or class names with the ALERename command.

ALEFileRename will rename file and fix import paths (tsserver only).

ALECodeAction will execute actions on the cursor or applied to a visual range selection, such as automatically fixing errors.

See :help ale-refactor for more information.

Installation

Add ALE to your runtime path in the usual ways.

If you have trouble reading :help ale, try the following.

packloadall | silent! helptags ALL

Vim packload:

mkdir -p ~/.vim/pack/git-plugins/start
git clone --depth 1 https://github.com/dense-analysis/ale.git ~/.vim/pack/git-plugins/start/ale

Neovim packload:

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

Windows packload:

# Run these commands in the "Git for Windows" Bash terminal
mkdir -p ~/vimfiles/pack/git-plugins/start
git clone --depth 1 https://github.com/dense-analysis/ale.git ~/vimfiles/pack/git-plugins/start/ale
Plug 'dense-analysis/ale'
Plugin 'dense-analysis/ale'
git clone https://github.com/dense-analysis/ale ~/.vim/bundle/ale
{
    'dense-analysis/ale',
    config = function()
        -- Configuration goes here.
        local g = vim.g

        g.ale_ruby_rubocop_auto_correct_all = 1

        g.ale_linters = {
            ruby = {'rubocop', 'ruby'},
            lua = {'lua_language_server'}
        }
    end
}

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 ALE and more check out the Dense Analysis Discord server here: https://discord.gg/5zFD6pQxDk

FAQ

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, you can define b:ale_linters for a single buffer, or g:ale_linters globally.

The recommended way to configure linters is to define a List in an ftplugin file.

" 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.

" In ~/.vim/vimrc, or somewhere similar.
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.

If you don't want ALE to run anything other than what you've explicitly asked for, you can set g:ale_linters_explicit to 1.

" Only run linters named in ale_linters settings.
let g:ale_linters_explicit = 1

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.

How do I disable a particular warning or error?

Warnings and errors should be configured in project configuration files for the relevant tools. ALE supports disabling only warnings relating to trailing whitespace, which Vim users often fix automatically.

" Disable whitespace warnings
let g:ale_warn_about_trailing_whitespace = 0

Users generally should not ignore warnings or errors in projects by changing settings in their own editor. Instead, configure tools appropriately so any other user of the same project will see the same problems.

How can I see what ALE has configured for the current file?

Run the following to see what is currently configured:

:ALEInfo

How can I disable virtual text appearing at ends of lines?

By default, ALE displays errors and warnings with virtual text. The problems ALE shows appear with comment-like syntax after every problem found. You can set ALE to only show problems where the cursor currently lies like so.

let g:ale_virtualtext_cursor = 'current'

If you want to disable virtual text completely, apply the following.

let g:ale_virtualtext_cursor = 'disabled'

How can I customise signs?

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

You can configure the sign gutter open at all times, if you wish.

let g:ale_sign_column_always = 1

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.

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
    • %...code...% is an optional error code, and most characters can be written between the % characters.
    • %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

See :help g:ale_echo_msg_format for more information.

How can I customise the statusline?

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.

vim-airline

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

Custom statusline

You can implement your own statusline function without adding any other plugins. ALE provides some functions to assist in this endeavour, including:

  • ale#statusline#Count: Which returns the number of problems found by ALE for a specified buffer.
  • ale#statusline#FirstProblem: Which returns a dictionary containing the full loclist details of the first problem of a specified type found by ALE in a buffer. (e.g. The first style warning in the current buffer.) This can be useful for displaying more detailed information such as the line number of the first problem in a file.

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() or :help ale#statusline#FirstProblem() for more information.

How can I change the borders for floating preview windows?

Borders for floating preview windows are enabled by default. You can use the g:ale_floating_window_border setting to configure them.

You could disable the border with an empty list.

let g:ale_floating_window_border = []

If the terminal supports Unicode, you might try setting the value like below, to make it look nicer.

let g:ale_floating_window_border = ['', '', '', '', '', '', '', '']

Since vim's default uses nice Unicode characters when possible, you can trick ale into using that default with

let g:ale_floating_window_border = repeat([''], 8)

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 behavior. Set g:ale_lint_on_text_changed to never. 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.

How can I use ALE with other LSP clients?

ALE offers an API for letting any other plugin integrate with ALE. If you are interested in writing an integration, see :help ale-lint-other-sources.

If you're running ALE in Neovim with nvim-lspconfig for configuring particular language servers. ALE will automatically disable its LSP functionality for any language servers configured with nvim-lspconfig by default. The following setting is applied by default:

let g:ale_disable_lsp = 'auto'

If you are running ALE in combination with another LSP client, you may wish to disable ALE's LSP functionality entirely. You can change the setting to 1 to always disable all LSP functionality.

let g:ale_disable_lsp = 1

You can also use b:ale_disable_lsp in your ftplugin files to enable or disable LSP features in ALE for different filetypes.

Neovim Diagnostics

If you are running Neovim 0.6 or later, you can make ALE display errors and warnings via the Neovim diagnostics API.

let g:ale_use_neovim_diagnostics_api = 1

coc.nvim

coc.nvim is a popular Vim plugin written in TypeScript and dependent on the npm ecosystem for providing full IDE features to Vim. Both ALE and coc.nvim implement Language Server Protocol (LSP) clients for supporting diagnostics (linting with a live server), and other features like auto-completion, and others listed above.

ALE is primarily focused on integrating with external programs through virtually any means, provided the plugin remains almost entirely written in Vim script. coc.nvim is primarily focused on bringing IDE features to Vim. If you want to run external programs on your files to check for errors, and also use the most advanced IDE features, you might want to use both plugins at the same time.

The easiest way to get both plugins to work together is to configure coc.nvim to send diagnostics to ALE, so ALE controls how all problems are presented to you, and to disable all LSP features in ALE, so ALE doesn't try to provide LSP features already provided by coc.nvim, such as auto-completion.

Open your coc.nvim configuration file with :CocConfig and add "diagnostic.displayByAle": true to your settings.

vim-lsp

vim-lsp is a popular plugin as implementation of Language Server Protocol (LSP) client for Vim. It provides all the LSP features including auto completion, diagnostics, go to definitions, etc.

vim-lsp-ale is a bridge plugin to solve the problem when using both ALE and vim-lsp. With the plugin, diagnostics are provided by vim-lsp and ALE can handle all the errors. Please read vim-lsp-ale's documentation for more details.

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

ALE runs its own autocmd events when a lint or fix cycle are started and stopped. There is also an event that runs when a linter job has been successfully started. These events can be used to call arbitrary functions during these respective parts of the ALE's operation.

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

    autocmd User ALEJobStarted call YourFunction()

    autocmd User ALEFixPre     call YourFunction()
    autocmd User ALEFixPost    call YourFunction()
augroup END

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.

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'
let g:ale_lint_on_insert_leave = 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

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.

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

You can also set let g:ale_list_vertical = 1 to open the windows vertically instead of the default horizontally.

Why isn't ALE checking my filetype?

stylelint for JSX

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 a jsx.vim ftplugin file.

" In ~/.vim/ftplugin/jsx.vim, or somewhere similar.
let b:ale_linter_aliases = ['css', 'javascript']
let b:ale_linters = ['stylelint', 'eslint']

Or if you want, you can configure the linters from your vimrc file.

" In ~/.vim/vimrc, or somewhere similar.
let g:ale_linter_aliases = {'jsx': ['css', 'javascript']}
let g:ale_linters = {'jsx': ['stylelint', 'eslint']}

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.

Checking Vue with ESLint

To check Vue files with ESLint, your ESLint project configuration file must be configured to use the Vue plugin. After that, you need to configure ALE so it will run the JavaScript ESLint linter on your files. The settings you need are similar to the settings needed for checking JSX code with both stylelint and ESLint, in the previous section.

" In ~/.vim/ftplugin/vue.vim, or somewhere similar.

" Run both javascript and vue linters for vue files.
let b:ale_linter_aliases = ['javascript', 'vue']
" Select the eslint and vls linters.
let b:ale_linters = ['eslint', 'vls']

Run :ALEInfo to see which linters are available after telling ALE to run JavaScript linters on Vue files. Not all linters support checking Vue files.

If you don't want to configure your linters in ftplugin files for some reason, you can configure them from your vimrc file instead.

" In ~/.vim/vimrc, or somewhere similar.
let g:ale_linter_aliases = {'vue': ['vue', 'javascript']}
let g:ale_linters = {'vue': ['eslint', 'vls']}

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, clangtidy and cquery 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.

ALE will attempt to parse compile_commands.json files to discover compiler flags to use when linting code. See :help g:ale_c_parse_compile_commands for more information. See Clang's documentation for compile_commands.json files. You should strongly consider generating them in your builds, which is easy to do with CMake.

You can also configure ALE to automatically run make -n to run dry runs on Makefiles to discover compiler flags. This can execute arbitrary code, so the option is disabled by default. See :help g:ale_c_parse_makefile.

How can I run linters or fixers via Docker or a VM?

ALE supports running linters or fixers via Docker, virtual machines, or in combination with any remote machine with a different file system, so long as the tools are well-integrated with ALE, and ALE is properly configured to run the correct commands and map filename paths between different file systems. See :help ale-lint-other-machines for the full documentation on how to configure ALE to support this.

ale's People

Contributors

andreypopp avatar atsuya avatar aurieh avatar benknoble avatar bstellato avatar charlesbjohnson avatar chaucerbao avatar daliusd avatar dmitrivereshchagin avatar donniewest avatar dsifford avatar elebow avatar fredemmott avatar hsanson avatar jeffwillette avatar jeremija avatar jhlink avatar jonhoo avatar jparise avatar kabbamine avatar kevinclark avatar kevinoid avatar neersighted avatar pinicarus avatar prashcr avatar rhysd avatar thindil avatar toastal avatar w0rp avatar zoonfafer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ale's Issues

Attempting to add support for PHP

Hello, I am trying to add support for php with php -l. I've added a directory called php to ale_linters and added a file called php.vim.

Here's my code so far:

if exists('g:loaded_ale_linters_php_php')
    finish
endif

let g:loaded_ale_linters_php_php = 1

function! ale_linters#php#php#Handle(buffer, lines)
    " Matches patterns like the following:
    "
    " Parse error: parse error in - on line 7
    let pattern = 'Parse error: \(.\+\) on line \(\d\+\)'
    let output = []

    for line in a:lines
        let l:match = matchlist(line, pattern)

        if len(l:match) == 0
            continue
        endif

        " vcol is Needed to indicate that the column is a character.
        call add(output, {
        \   'bufnr': a:buffer,
        \   'lnum': l:match[1] + 0,
        \   'vcol': 0,
        \   'col': 0,
        \   'text': l:match[0],
        \   'type': 'E',
        \   'nr': -1,
        \})
    endfor

    return output
endfunction

call ALEAddLinter('php', {
\   'name': 'php',
\   'executable': 'php',
\   'output_stream': 'stderr',
\   'command': 'php -l -',
\   'callback': 'ale_linters#php#php#Handle',
\})

When I run cat myfile.php | php -l I get sytnax errors. But in the buffer nothing shows up.

Errors when using ALEGetStatusLine() with airline

Hi @w0rp, I may be wrong but I noticed that when i'm using ALEGetStatusLine() function with airline like this:
let g:airline_section_error = '%{ALEGetStatusLine()}'
then it works good for file types for which i have installed linters, but for other filetypes it throws errors:

E117: Unknown function: ALEGetStatusLine
E15: Invalid expression: ALEGetStatusLine()

I made a screencast with the actual behaviour https://asciinema.org/a/abbk4amukbzrvmgskyjesusd1

Install docs would be useful

Currently nothing exists to help a new user to setup the plugin.

Vundle? Pathogen? Required vimrc changes etc etc.

Alias system required

With my lazy-loading work (and indeed, before it, in the case of the sh linter), shell linter, linters which support multiple file-types are not actually used.

This is presently the case for jsx and zsh. Two solutions are obvious:

  • Create symlinks (easiest and simplest, in my opinion)
  • Create an alias table

I think the symlink approach is more elegant, as it avoids referencing any linters in the core, and can be trivially and transparently managed, eg ln -s ale_linters/sh/shell.vim ale_linters/zsh/shell.vim.

Thoughts?

Gitgutter is overwritten by ale

When using the gitgutter plugin, which adds git changed/added/removed annotations to the left gutter, ale seems to be in competition for the gutter space. I see gitgutter's annotations flash briefly, and are then overwritten when ale finishes processing with either nothing, or with whatever syntax issues ale found.

Readme updates

Just noting the README needs to be updated with new flags/options, examples such as how to alias filetypes, and that the statusline function needs to be updated.

Refactoring

Actually, the plugin is getting bigger and bigger, so IMO we should make some refactoring for the next versions.

  • Create a directory structure more vimish, e.g:
├── ale_linters/
├── lib(scripts?)/
│   ├── stdin-wrapper
│   └── dmd-wrapper
├── doc/
│   ├── ale.txt
├── plugin/
│   └── ale.vim (content of zmain and maybe aaflags.vim)
├── autoload/
│   ├── ale.vim
│   └── ale/
│       ├── aaflags.vim
│       ├── cursor.vim
│       ├── handlers.vim
│       ├── sign.vim
│       ├── util.vim
├── example.gif
├── LICENSE
├── CONTRIBUTING.md
└── README.md
  • Use local variables & functions when we can.
  • Document everything.
  • Test cases, using Vader or the vim 8 testing framework (#7)
  • Use an OOP approach (Not mandatory but make the code more readable)
  • Follow the google Vimscript Style Guide (Vint is following this guide).

What do you think @w0rp?

Go support

golint and go vet support would be great.

They have relatively simple output -- I would guess golint would produce warnings and go vet errors.

Global variables

Is there any reason for us to use global variables, as opposed to buffer-scoped variables? I think buffer-scoped variables make more sense for our use case, and could be used to simplify much of the code.

Write help files in English

This project needs some help files for the :help command to explain the plugins, and perhaps some of the options. I might also additionally add a section to the README file for the various flags you can set in your vimrc file. The API for adding linters should be explained in detail.

Lessons Learned from Syntastic

Hey there, @w0rp thanks for your work on this.
I just read this thread: vim-syntastic/syntastic#699 and it is VERY INFORMATIVE on the limitations vim has and how far can Syntastic go. He mentions the flaws that they only found out later and etc and still many plugin developers commit the same errors.

So I thought you would like to know those (in case you don't already)...

Cheers

Add quickfix support

I addeed loclist support on day 1, but not quickfix list support. Some people will probably like to use the quickfix list. Some support should be added for populating the quickfix list, and for automatically opening the list when there are errors.

Write an option for choosing which linters are run

An option for choosing which linters are run in a vimrc file should be added. The option should look like the following:

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

The plugin should by default attempt to run every linter which can be run when a language is not specified, or the option is not given at all. When a language is specified, only the linters named in each array should be run when analysing a file.

Sometimes tidy does not lint html files on BufEnter event

A strange behavior that can occur randomly.
When opening an existing file, there is no linting before the file is modified.

ale

With verbose set to a high value, I've seen that ALELint(0) is called correctly on BufEnter but no linting so far.

I've tested with a clean vimrc with only ale and different file types, and same issue.


EDIT:

The code from the gif:

<!DOCTYPE html>
<html lang="fr">

  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width; initial-scale:1.0; maximum-scale=1.0">
    <title>A simple title</title>
  </head>

  <body>
    <h1>Foo/h2>
    <p>Sit magni quo cum fugit tenetur commodi Eum labore facilis.
  </body>

</html>

What about the tools not reading from stdin?

I would like to add many linters that unfortunately do not read from stdin (csslint, sass-lint, vint...). Is there any plans or strategy to handle those kind of tools in ale?

In fact, I can easily add them to validator but I prefer to use a solution full vimscript as your plugin.

A string for the statusline

A function returning a string usable by the statusline will be very useful (like validator or syntastic does). Should we wait for a stable API before implementing it?

Set up Travis CI Testing

I have never set up Vim plugin testing on Travis CI before, but I believe it would be wise to set up some CI for this plugin to ensure that the various linters will continue to work, if at all possible.

Vader seems to be the tool to go for, from my limited amount of research. There is also an RSpec option. I do not know what will work best for this at the moment.

If anyone has any suggestions on this, please let me know.

E631: write_buf_line()(): write failed

While using ale in MacVim GUI this message appears in the command line very very frequently. There are also some others I am seeing with a simple .vimrc

set nocompatible
set nu
set runtimepath+=~/.vim.old/neobundles/ale
E631: write_buf_line()(): write failed
E631: write_buf_line()(): write failed
Error detected while processing function <SNR>20_TimerHandler[22]..<SNR>20_ApplyLinter[3]..<SNR>20_ClearJob:
line    1:
E716: Key not present in Dictionary: process 25042 dead
E15: Invalid expression: s:job_info_map[a:job].linter
line   15:
E716: Key not present in Dictionary: process 25042 dead
line   16:
E121: Undefined variable: linter
E116: Invalid arguments for function remove
line    1:
E716: Key not present in Dictionary: process 25043 dead
E15: Invalid expression: s:job_info_map[a:job].linter
line   15:
E716: Key not present in Dictionary: process 25043 dead
line   16:
E121: Undefined variable: linter
E116: Invalid arguments for function remove
E631: write_buf_line()(): write failed
E631: write_buf_line()(): write failed
E631: write_buf_line()(): write failed
E631: write_buf_line()(): write failed 

Vim Version is 8.0.020 and there is no .vim/ for this test (as seen above only ale is being added manually).

Cannot use jshintrc file

I went through the jshint.vim code and saw it was supposed to either detect a .jshintrc file in the parent directories of the current file, or use the one specified in a global configuration variable.

I did some digging around (not a vimscript expert) and found that the if jshint_config check at (https://github.com/w0rp/ale/blob/master/ale_linters/javascript/jshint.vim#L22) does not work, it should be (according to me) if !empty(jshint_config)

I changed that, but then it was still not OK, so I dug a bit deeper and found that removing the shellescape part at the next line (https://github.com/w0rp/ale/blob/master/ale_linters/javascript/jshint.vim#L23) fixes it. However, I'm not sure if this is the right way to go (the shellescape is there for a reason I guess), that's why I did not create a pull request.

Add Windows support

Support should be added for running pretty much all of the linters in Windows.

I am working on this now. I initially tried writing a Windows variant of the stdin-wrapper as a Batch script, but it didn't go so well, as Batch is pretty awful. My plan now is to write the wrapper in D, and include a portable .exe file for Windows in this repo. After that is done, there will be some further adjustments to make, around dealing with strange Windows shell escaping issues.

bundle exec for rubocop

Hey,

I had to override ruby linter command to 'bundle exec rubocop...' but maybe it should be available in configuration.

Make a cool logo for "ALE"

I would like to put a cool logo for the project in the README file to show on GitHub. I possess basically no skills for making that kind of art myself. If anyone wants to give it a go, I'll accept any contributions.

Eslint incompatibility with vim-jsx

Hey there!

First and foremost, thank you so much for your hard and fast work on this plugin, it's really great.

I've ran into the most peculiar issue with using ale and eslint, where the linter will break only when the vim-jsx plugin is simultaneously included. Thought I'd bring it to attention here, although I've no idea why it might be happening or how to go about tracing stacks etc., to try fix it.

To replicate

  • Include vim-jsx via some plugin manager, along with ale.

Thanks,
J.

How to specify bash for sh files

I want to use only bash to lint sh files (I still have shellcheck installed and don't want to use for now), so which one of the following should I use?

" It should be after the linter name, which is 'shell'
let g:ale_linters = {'sh': ['shell']}

let g:ale_linters = {'sh': ['bash']}

Note that none of the above works.

Fix a format for echoed string

Now each linter use its own format for the echoed message, so it will be great to decide and specify only one format to use.

IMHO something like that will be good:

When we know the severity

:[linter-name] Severity - Text

And when we don't know:

:[linter-name] Text

Note that the 1st letter of severity/text is in capital.
I'm thinking that linter-name can be helpful for the file types using multiple ones.

@w0rp If you agree, I can make a PR.

Feature Request: Lint on save

Would it be possible to create a rule to lint on save only? I tried setting let g:ale_lint_on_text_changed = 0 but then no linting occurs; ideally I would like to only lint on each save so that I have a chance to do everything on my own first and then am alerted of anything I missed (when I save) rather than right away; I considered increasing g:ale_lint_delay but I want the lint to be immediate, just only on save, not right while I am in the middle of typing and fixing things I already know wont work.

So, something like this:
image

p.s. thanks for a fantastic plugin! I was glad to make the switch from Syntastic to the Vim 8 async goodness.

Create better default signs

I wrote this plugin with some signs which are easy to differentiate, but which don't look the best. I think the plugin could use some better default signs and colours, etc. If anyone has found some better characters and colours to use for errors and warnings, let me know.

Additionally, if anyone can think of a nicer looking GIF to put in the README file with some nicer looking signs, I'll take that.

Jobs should be tracked seperately

Getting an error on the latest master:

Error detected while processing function <SNR>105_HandleExitNeoVim[1]..<SNR>105_HandleExit:
line   29:
E716: Key not present in Dictionary: 1
E15: Invalid expression: g:ale_buffer_should_reset_map[l:buffer]

Add powerline segment(s)

I'm going to write powerline segments to display the file status and error message for powerline, like the ones for syntastic.

What API would be the best to query the location of the first and total number of errors and warnigs respectively?

Maybe there should be some lower-level interface of ale#statusline#Status(), it seems very redundant to re-do all that access and sorting logic in python to display it (compare to the syntastic API: g:SyntasticLoclist.current().errors(), g:SyntasticLoclist.current().hasErrorsOrWarningsToDisplay())

Linters for Elixir

  • Elixir (not always useful messages)
  • Credo
  • Dogma (cannot accept files from stdin and covers the same area as mix credo --strict)

The signs are not updated

Is it just for me or what? Starting from 6754b9f, the signs are not updated.

ale

You can see in the gif above that even after correcting the error, the sign is still there.
Reverting back to aebf8e0 make the signs work as expected.

Add coding standards to `CONTRIBUTING.md`

The coding standards should be added to the CONTRIBUTING.md file so everyone knows the rules around indentation, and other parts of syntax humans moan about endlessly.

Feature request: statusline lint status option

Would be cool if there was something available to add to the statusline to show lint status; for reference, Syntastic has this:
image

p.s. Thanks for the great work on ALE! I'm really liking it so far; the Vim 8 async is much better than Syntastic and I appreciate that this plugin is more modern + lightweight.

Add comment headers to each source file

Comment headers to each source file should be added. Most importantly, the authors of each file should be credited in each file. This will help especially as others contribute to the project.

Nothing beign echo'ed when over error

Hey, trying out ALE now, but it doesn't seem to echo errors nor highlight them when something is wrong. Using vim 8.0 1-22 with newest version of ALE (as of now). No errors or such, I am however using YCM if that could matter. I can post my config if you need, but it's only stuff from the readme.

Write important tests

I'll list some important tests we should write to kick off the Vader test suite.

  • Unit test the loclist sorting.
  • Unit test the loclist binary search.
  • Unit test handlers in handlers.vim
  • Test that we echo the correct errors based on the cursor position. (Multiple errors on the same line)
  • Test that running a linter on a file updates the loclist
  • Test that running a linter on a file updates the signs
  • Test that linters run when files are opened.
  • Test that linters run when the TextChanged event is fired.
  • Test that linters run when files are saved, when that option is on.
  • Test the status function. (This can probably be tested by setting the buffer loclist global)
  • Test the nearest file search
  • Test cleanup of variables
  • Test the behaviour of g:ale_linters with the Get function.
  • Test the behaviour of g:ale_linter_aliases with the Get function.
  • Test doautocmd behaviour implemented in #104

Some input on Airline

Hey there, I just (vim-airline/vim-airline#1286) posted a PR adding support for ale to vim-airline. Could you take a look on it, and comment on the approach/code?

Alternately, if you feel the API is unstable or it would be better maintained here, it can be included as a part of ale with only minor changes.

Thanks!

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.