" Per-file lint entrypoint used by lf / :LintFile function! s:lint_file() abort let l:ft = &filetype let l:filepath = expand('%:p') if empty(l:filepath) echohl WarningMsg echom 'LintFile: no file to lint' echohl None return endif if index(['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'svelte', 'astro'], l:ft) >= 0 if exists('*CocAction') try call CocAction('runCommand', 'eslint.executeAutofix') echom 'LintFile: eslint autofix via CoC' return catch /.*/ endtry endif let l:eslint = findfile('node_modules/.bin/eslint', '.;') if !empty(l:eslint) execute 'silent !' . fnameescape(fnamemodify(l:eslint, ':p')) . ' --fix ' . shellescape(l:filepath) checktime edit echom 'LintFile: eslint --fix (local)' return endif echohl WarningMsg echom 'LintFile: eslint not found (CoC command failed and no local node_modules/.bin/eslint)' echohl None return endif if index(['terraform', 'tf', 'hcl'], l:ft) >= 0 if executable('tflint') execute 'silent !tflint --chdir ' . shellescape(expand('%:p:h')) echom 'LintFile: tflint' else echohl WarningMsg echom 'LintFile: tflint not installed' echohl None endif return endif if l:ft ==# 'java' echom 'LintFile: Java diagnostics come from coc-java (JDTLS)' return endif echom 'LintFile: no linter configured for filetype "' . l:ft . '"' endfunction command! LintFile call lint_file()