Ale: Disable linter error check when configuration is not found.

Created on 2 Oct 2017  路  6Comments  路  Source: dense-analysis/ale

How to disable linter in ale (in my case eslint), if there was no eslint configuration found.

I sometimes edit standalone file scripts, where linter is not configured, and I don't have eslint globally configured.

Most helpful comment

I have added an option, which can be configured per buffer, for disabling specifically this error. See :help g:ale_javascript_eslint_suppress_missing_config. Be warned that turning this option on will mean that you won't be told when you're missing a configuration file for your project.

All 6 comments

I recommend disabling ESLint for particular files. Consult the documentation for :help g:ale_linters and :help g:ale_pattern_options.

@w0rp thank for the answer. I know this option, but it will be extremely annoying to configure pattern for every file you want to edit. Moreover, the same file can appear twice in different projects and you want linter for one of it.

You can use regular expressions, so you can configure many things in one go.

@krhubert
You can use this in your vimrc to get that functionality:

autocmd FileType javascript let g:ale_linters = findfile('.eslintrc', '.;') != '' ? {'javascript': ['eslint']} : {'javascript': ['']}

I found this ages ago for syntastic, but seemingly works for anything esle :)

I have added an option, which can be configured per buffer, for disabling specifically this error. See :help g:ale_javascript_eslint_suppress_missing_config. Be warned that turning this option on will mean that you won't be told when you're missing a configuration file for your project.

BTW, here is some code which takes a glob pattern (e.g. .eslintrc.*) instead of just a string (findfile does not support globs):

" Only lint if .eslintrc is present
autocmd FileType javascript let g:ale_linters = FindGlob('.eslintrc.*', expand('%:p:h')) ? {'javascript': ['eslint']} : {'javascript': ['']}

function! g:FindGlob(pattern, path)
  let fullpattern = a:path . "/" . a:pattern
  if strlen(glob(fullpattern))
    return 1
  else
    let parts = split(a:path, "/")
    if len(parts)
      let newpath = "/" . join(parts[0:-2], "/")
      return FindGlob(a:pattern, newpath)
    else
      return 0
    endif
  endif
endfunction

Probably atrocious vimscript because I don't have much experience with the language, but hey, it works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chauncey-garrett picture chauncey-garrett  路  3Comments

garand picture garand  路  4Comments

trevordmiller picture trevordmiller  路  3Comments

sodiumjoe picture sodiumjoe  路  4Comments

plexigras picture plexigras  路  3Comments