aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/eslint.lua51
1 files changed, 43 insertions, 8 deletions
diff --git a/lua/lspconfig/eslint.lua b/lua/lspconfig/eslint.lua
index a3ddfd17..54d17d21 100644
--- a/lua/lspconfig/eslint.lua
+++ b/lua/lspconfig/eslint.lua
@@ -54,21 +54,37 @@ configs.eslint = {
'typescriptreact',
'typescript.tsx',
},
- root_dir = util.root_pattern('.eslintrc.json', '.eslintrc.js', 'package.json', 'tsconfig.json', '.git'),
+ -- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats
+ root_dir = util.root_pattern(
+ '.eslintrc.js',
+ '.eslintrc.cjs',
+ '.eslintrc.yaml',
+ '.eslintrc.yml',
+ '.eslintrc.json',
+ 'package.json'
+ ),
+ -- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation.
settings = {
- validate = 'off',
+ validate = 'on',
packageManager = 'npm',
useESLintClass = false,
codeActionOnSave = {
enable = false,
mode = 'all',
},
- format = false,
+ format = true,
quiet = false,
onIgnoredFiles = 'off',
rulesCustomizations = {},
run = 'onType',
- nodePath = vim.NIL,
+ -- If nodePath is a non-null/undefined value the eslint LSP runs into runtime exceptions.
+ --
+ -- It's recommended not to change this.
+ nodePath = '',
+ -- Automatically determine working directory by locating .eslintrc config files.
+ --
+ -- It's recommended not to change this.
+ workingDirectory = { mode = 'auto' },
codeAction = {
disableRuleComment = {
enable = true,
@@ -79,13 +95,26 @@ configs.eslint = {
},
},
},
+ on_new_config = function(config, new_root_dir)
+ -- The "workspaceFolder" is a VSCode concept. It limits how far the
+ -- server will traverse the file system when locating the ESLint config
+ -- file (e.g., .eslintrc).
+ config.settings.workspaceFolder = {
+ uri = new_root_dir,
+ name = vim.fn.fnamemodify(new_root_dir, ':t'),
+ }
+ end,
handlers = {
['eslint/openDoc'] = function(_, result)
if not result then
return
end
- vim.cmd('!open ' .. result.url)
- return {}
+ local sysname = vim.loop.os_uname().sysname
+ if sysname:match 'Windows' then
+ os.execute(string.format('start %q', result.url))
+ else
+ os.execute(string.format('open %q', result.url))
+ end
end,
['eslint/confirmESLintExecution'] = function(_, result)
if not result then
@@ -93,6 +122,12 @@ configs.eslint = {
end
return 4 -- approved
end,
+ ['eslint/probeFailed'] = function()
+ vim.notify('ESLint probe failed.', vim.log.levels.WARN)
+ end,
+ ['eslint/noLibrary'] = function()
+ vim.notify('Unable to find ESLint library.', vim.log.levels.WARN)
+ end,
},
},
commands = {
@@ -121,8 +156,8 @@ autocmd BufWritePre <buffer> <cmd>EslintFixAll<CR>
See [vscode-eslint](https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L216-L229) for configuration options.
-Additional messages you can handle: eslint/probeFailed, eslint/noLibrary, eslint/noConfig
-Messages already handled in lspconfig: eslint/openDoc, eslint/confirmESLintExecution
+Additional messages you can handle: eslint/noConfig
+Messages already handled in lspconfig: eslint/openDoc, eslint/confirmESLintExecution, eslint/probeFailed, eslint/noLibrary
]],
},
}