diff options
| author | Raphael <glepnir@neovim.pro> | 2022-10-21 19:03:56 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-21 19:03:56 +0800 |
| commit | ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691 (patch) | |
| tree | 72d64b96e4054d08c18e8d9e28ded0ba9a9bdd32 /lua | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.tar nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.tar.gz nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.tar.bz2 nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.tar.lz nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.tar.xz nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.tar.zst nvim-lspconfig-ee2e8c63cff0a8bfc7f4ef985ea466f10bb7e691.zip | |
fix: check the package.json has eslintConfig field for eslint (#2208)
* fix: check the package.json has eslintConfig field for eslint
* fix: remove duplicate windows check
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/eslint.lua | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/lua/lspconfig/server_configurations/eslint.lua b/lua/lspconfig/server_configurations/eslint.lua index 43482f6e..7f2d34cd 100644 --- a/lua/lspconfig/server_configurations/eslint.lua +++ b/lua/lspconfig/server_configurations/eslint.lua @@ -1,5 +1,6 @@ local util = require 'lspconfig.util' local lsp = vim.lsp +local is_windows = vim.fn.has 'win32' == 1 local function fix_all(opts) opts = opts or {} @@ -35,10 +36,38 @@ end local bin_name = 'vscode-eslint-language-server' local cmd = { bin_name, '--stdio' } -if vim.fn.has 'win32' == 1 then +if is_windows then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local root_file = { + '.eslintrc', + '.eslintrc.js', + '.eslintrc.cjs', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + 'package.json', +} + +local root_with_package = util.find_package_json_ancestor(vim.fn.expand '%:p:h') + +if root_with_package then + local must_remove = false + local path_sep = is_windows and '\\' or '/' + for line in io.lines(root_with_package .. path_sep .. 'package.json') do + if line:find 'eslintConfig' then + must_remove = false + else + must_remove = true + end + end + + if must_remove then + table.remove(root_file, #root_file) + end +end + return { default_config = { cmd = cmd, @@ -54,15 +83,7 @@ return { 'astro', }, -- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats - root_dir = util.root_pattern( - '.eslintrc', - '.eslintrc.js', - '.eslintrc.cjs', - '.eslintrc.yaml', - '.eslintrc.yml', - '.eslintrc.json', - 'package.json' - ), + root_dir = util.root_pattern(unpack(root_file)), -- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation. settings = { validate = 'on', |
