diff --git a/README.md b/README.md index a26a8d4..f739ee5 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ - [x] [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) - [ ] [codespell](https://github.com/codespell-project/codespell) +- [ ] [eslint](https://eslint.org/) +- [ ] [eslint_d](https://github.com/mantoni/eslint_d.js) - [x] [flake8](https://github.com/PyCQA/flake8) - [x] [hadolint](https://github.com/hadolint/hadolint) - [x] [luacheck](https://github.com/lunarmodules/luacheck) diff --git a/lua/guard-collection/linter/eslint.lua b/lua/guard-collection/linter/eslint.lua new file mode 100644 index 0000000..6776077 --- /dev/null +++ b/lua/guard-collection/linter/eslint.lua @@ -0,0 +1,33 @@ +local lint = require('guard.lint') + +return { + cmd = 'eslint', + args = { '--format', 'json', '--stdin', '--stdin-filename' }, + stdin = true, + fname = true, + find = { + '.eslintrc.js', + '.eslintrc.cjs', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + }, + parse = lint.from_json({ + get_diagnostics = function(...) + return vim.json.decode(...)[1].messages + end, + attributes = { + lnum = 'line', + end_lnum = 'endLine', + col = 'column', + end_col = 'endColumn', + message = 'message', + code = 'ruleId', + }, + severities = { + lint.severities.warning, + lint.severities.error, + }, + source = 'eslint', + }), +} diff --git a/lua/guard-collection/linter/eslint_d.lua b/lua/guard-collection/linter/eslint_d.lua new file mode 100644 index 0000000..5a1f4bb --- /dev/null +++ b/lua/guard-collection/linter/eslint_d.lua @@ -0,0 +1,33 @@ +local lint = require('guard.lint') + +return { + cmd = 'eslint_d', + args = { '--format', 'json', '--stdin', '--stdin-filename' }, + stdin = true, + fname = true, + find = { + '.eslintrc.js', + '.eslintrc.cjs', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + }, + parse = lint.from_json({ + get_diagnostics = function(...) + return vim.json.decode(...)[1].messages + end, + attributes = { + lnum = 'line', + end_lnum = 'endLine', + col = 'column', + end_col = 'endColumn', + message = 'message', + code = 'ruleId', + }, + severities = { + lint.severities.warning, + lint.severities.error, + }, + source = 'eslint_d', + }), +} diff --git a/lua/guard-collection/linter/init.lua b/lua/guard-collection/linter/init.lua index 0cb5697..3c6227e 100644 --- a/lua/guard-collection/linter/init.lua +++ b/lua/guard-collection/linter/init.lua @@ -1,6 +1,8 @@ return { ['clang-tidy'] = require('guard-collection.linter.clang-tidy'), codespell = require('guard-collection.linter.codespell'), + eslint = require('guard-collection.linter.eslint'), + eslint_d = require('guard-collection.linter.eslint_d'), flake8 = require('guard-collection.linter.flake8'), hadolint = require('guard-collection.linter.hadolint'), luacheck = require('guard-collection.linter.luacheck'),