Skip to content

Commit

Permalink
fix: check the package.json has eslintConfig field for eslint (neovim…
Browse files Browse the repository at this point in the history
…#2208)

* fix: check the package.json has eslintConfig field for eslint

* fix: remove duplicate windows check
  • Loading branch information
glepnir authored Oct 21, 2022
1 parent 3592f76 commit ee2e8c6
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions lua/lspconfig/server_configurations/eslint.lua
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down

0 comments on commit ee2e8c6

Please sign in to comment.