From e7c7785cc5ac98d93e07073a5ffb3fce4f07b8e4 Mon Sep 17 00:00:00 2001 From: "asep.komarudin" Date: Thu, 4 Jul 2024 20:52:02 +0700 Subject: [PATCH] enc: add auto lint nvim-lint --- lazy-lock.json | 9 +- lua/plugins/autolint.lua | 37 ++++++ lua/plugins/nvimlint.lua | 262 +++++++++++++++++++-------------------- 3 files changed, 173 insertions(+), 135 deletions(-) create mode 100644 lua/plugins/autolint.lua diff --git a/lazy-lock.json b/lazy-lock.json index cac87c4..09c3128 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -2,7 +2,8 @@ "Comment.nvim": { "branch": "master", "commit": "e51f2b142d88bb666dcaa77d93a07f4b419aca70" }, "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" }, - "auto-conform.nvim": { "branch": "main", "commit": "08f9b7b43c847159413d64e5a793fe0b6ccb7d62" }, + "auto-conform.nvim": { "branch": "main", "commit": "8d2fbcbd8b8dfd44e1bc2edffc3fe7372b5b520e" }, + "auto-lint.nvim": { "branch": "main", "commit": "fa2c16211524e965242196e55b1f748d63332dcd" }, "bigfile.nvim": { "branch": "main", "commit": "33eb067e3d7029ac77e081cfe7c45361887a311a" }, "bufferline.nvim": { "branch": "main", "commit": "81820cac7c85e51e4cf179f8a66d13dbf7b032d9" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, @@ -21,7 +22,7 @@ "indent-blankline.nvim": { "branch": "master", "commit": "65e20ab94a26d0e14acac5049b8641336819dfc7" }, "lazy.nvim": { "branch": "main", "commit": "cea5920abb202753004440f94ec39bcf2927e02e" }, "live-server.nvim": { "branch": "main", "commit": "f34ae262bf046981d9e5f7cd4f41a353a9647a22" }, - "lsp-progress.nvim": { "branch": "main", "commit": "55a04895ea20c365b670051a3128265d43bdfa3d" }, + "lsp-progress.nvim": { "branch": "main", "commit": "c5858bba2043cac5ad4113fe1263366125b1b314" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" }, "mason-nvim-dap.nvim": { "branch": "main", "commit": "4ba55f9755ebe8297d92c419b90a946123292ae6" }, @@ -42,9 +43,9 @@ "nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" }, "nvim-nio": { "branch": "master", "commit": "7969e0a8ffabdf210edd7978ec954a47a737bbcc" }, "nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" }, - "nvim-scrollview": { "branch": "main", "commit": "06563ae0c9928a2df42aefe66f2aed2f2943e32e" }, + "nvim-scrollview": { "branch": "main", "commit": "30ca6e18265928eb4ea7402346b4dfddbd8ce41e" }, "nvim-tree.lua": { "branch": "master", "commit": "2086e564c4d23fea714e8a6d63b881e551af2f41" }, - "nvim-treesitter": { "branch": "master", "commit": "caf275382f91ec8a2498d455c4d7d3fd0265ebd3" }, + "nvim-treesitter": { "branch": "master", "commit": "acc1708b962e12cc1d671cd530782727801804c3" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, "nvim-ts-autotag": { "branch": "main", "commit": "ddfccbf0df1b9349c2b9e9b17f4afa8f9b6c1ed1" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "2b7dcf6aab0947b9c4195f1d8aa592cdcd944ffe" }, diff --git a/lua/plugins/autolint.lua b/lua/plugins/autolint.lua new file mode 100644 index 0000000..afda660 --- /dev/null +++ b/lua/plugins/autolint.lua @@ -0,0 +1,37 @@ +local M = {} +local disable = pcode.disable_null_ls or false +if require("user.utils.cfgstatus").cheack() then + disable = true +end +if disable then + M = { + "pojokcodeid/auto-lint.nvim", + dependencies = { + "mfussenegger/nvim-lint", + }, + event = "VeryLazy", + config = function() + require("auto-lint").setup({ + map_lang = { + -- ["c++"] = "cpp", + -- ["c#"] = "cs", + }, + map_name = { + -- ["actionlint"] = "actionlint", + -- ["ansible_lint"] = "ansible_lint", + }, + add_new = { + -- ["typescriptreact"] = { "eslint_d" }, + -- ["javascriptreact"] = { "eslint_d" }, + }, + ignore = { + -- ["php"] = { "tlint" }, + }, + ensure_installed = { + -- "eslint_d", + }, + }) + end, + } +end +return M diff --git a/lua/plugins/nvimlint.lua b/lua/plugins/nvimlint.lua index ecd18e1..9b2f524 100644 --- a/lua/plugins/nvimlint.lua +++ b/lua/plugins/nvimlint.lua @@ -1,133 +1,133 @@ local M = {} -local disable = pcode.disable_null_ls or false -if require("user.utils.cfgstatus").cheack() then - disable = true -end -if disable then - M = { - "mfussenegger/nvim-lint", - event = { "BufReadPre", "BufNewFile" }, - opts = function(_, opts) - local mason_reg = require("mason-registry") - - opts.linters_by_ft = opts.linters_by_ft or {} - - -- add diff langue vs filetype - local keymap = { - ["c++"] = "cpp", - ["c#"] = "cs", - } - - -- add dif nvim-lint vs mason - local name_map = { - ["actionlint"] = "actionlint", - ["ansible_lint"] = "ansible_lint", - ["buf"] = "buf_lint", - ["buildifier"] = "buildifier", - ["cfn-lint"] = "cfn_lint", - ["checkstyle"] = "checkstyle", - ["clj-kondo"] = "clj_kondo", - ["cmakelint"] = "cmakelint", - ["codespell"] = "codespell", - ["cpplint"] = "cpplint", - ["cspell"] = "cspell", - ["curlylint"] = "curlylint", - ["djlint"] = "djlint", - ["erb-lint"] = "erb_lint", - ["eslint_d"] = "eslint_d", - ["flake8"] = "flake8", - ["gdtoolkit"] = "gdlint", - ["golangci-lint"] = "golangcilint", - ["hadolint"] = "hadolint", - ["jsonlint"] = "jsonlint", - ["ktlint"] = "ktlint", - ["luacheck"] = "luacheck", - ["markdownlint"] = "markdownlint", - ["mypy"] = "mypy", - ["phpcs"] = "phpcs", - ["phpmd"] = "phpmd", - ["phpstan"] = "phpstan", - ["proselint"] = "proselint", - ["pydocstyle"] = "pydocstyle", - ["pylint"] = "pylint", - ["revive"] = "revive", - ["rstcheck"] = "rstcheck", - ["rubocop"] = "rubocop", - ["ruff"] = "ruff", - ["selene"] = "selene", - ["shellcheck"] = "shellcheck", - ["sqlfluff"] = "sqlfluff", - ["standardrb"] = "standardrb", - ["stylelint"] = "stylelint", - ["solhint"] = "solhint", - ["tflint"] = "tflint", - ["tfsec"] = "tfsec", - ["trivy"] = "trivy", - ["vale"] = "vale", - ["vint"] = "vint", - ["vulture"] = "vulture", - ["yamllint"] = "yamllint", - } - - -- add new mapping filetype - local addnew = { - ["typescriptreact"] = "eslint_d", - ["javascriptreact"] = "eslint_d", - ["javascript.jsx"] = "eslint_d", - ["typescript.tsx"] = "eslint_d", - ["vue"] = "eslint_d", - ["sevelte"] = "eslint_d", - ["astro"] = "eslint_d", - } - - local ignore = { - ["php"] = "tlint", - } - - -- local listtest = {} - for _, pkg in pairs(mason_reg.get_installed_packages()) do - for _, type in pairs(pkg.spec.categories) do - -- only act upon a Linter - if type == "Linter" then - -- finally add the linter to it's compatible filetype(s) - for _, ft in pairs(pkg.spec.languages) do - local ftl = string.lower(ft) - local ready = mason_reg.get_package(pkg.spec.name):is_installed() - if ready then - if keymap[ftl] ~= nil then - ftl = keymap[ftl] - end - - -- if substring(pkg.spec.name, "eslint") then - -- table.insert(listtest, ftl) - -- end - - if name_map[pkg.spec.name] ~= nil then - pkg.spec.name = name_map[pkg.spec.name] - end - - -- add new mapping language - for key, value in pairs(addnew) do - if value == pkg.spec.name then - opts.linters_by_ft[key] = opts.linters_by_ft[key] or {} - table.insert(opts.linters_by_ft[key], pkg.spec.name) - end - end - - if ignore[ftl] ~= pkg.spec.name then - opts.linters_by_ft[ftl] = opts.linters_by_ft[ftl] or {} - table.insert(opts.linters_by_ft[ftl], pkg.spec.name) - end - end - end - end - end - end - -- print(table.concat(listtest, ",")) - end, - config = function(_, opts) - require("lint").linters_by_ft = opts.linters_by_ft - end, - } -end +-- local disable = pcode.disable_null_ls or false +-- if require("user.utils.cfgstatus").cheack() then +-- disable = true +-- end +-- if disable then +-- M = { +-- "mfussenegger/nvim-lint", +-- event = { "BufReadPre", "BufNewFile" }, +-- opts = function(_, opts) +-- local mason_reg = require("mason-registry") +-- +-- opts.linters_by_ft = opts.linters_by_ft or {} +-- +-- -- add diff langue vs filetype +-- local keymap = { +-- ["c++"] = "cpp", +-- ["c#"] = "cs", +-- } +-- +-- -- add dif nvim-lint vs mason +-- local name_map = { +-- ["actionlint"] = "actionlint", +-- ["ansible_lint"] = "ansible_lint", +-- ["buf"] = "buf_lint", +-- ["buildifier"] = "buildifier", +-- ["cfn-lint"] = "cfn_lint", +-- ["checkstyle"] = "checkstyle", +-- ["clj-kondo"] = "clj_kondo", +-- ["cmakelint"] = "cmakelint", +-- ["codespell"] = "codespell", +-- ["cpplint"] = "cpplint", +-- ["cspell"] = "cspell", +-- ["curlylint"] = "curlylint", +-- ["djlint"] = "djlint", +-- ["erb-lint"] = "erb_lint", +-- ["eslint_d"] = "eslint_d", +-- ["flake8"] = "flake8", +-- ["gdtoolkit"] = "gdlint", +-- ["golangci-lint"] = "golangcilint", +-- ["hadolint"] = "hadolint", +-- ["jsonlint"] = "jsonlint", +-- ["ktlint"] = "ktlint", +-- ["luacheck"] = "luacheck", +-- ["markdownlint"] = "markdownlint", +-- ["mypy"] = "mypy", +-- ["phpcs"] = "phpcs", +-- ["phpmd"] = "phpmd", +-- ["phpstan"] = "phpstan", +-- ["proselint"] = "proselint", +-- ["pydocstyle"] = "pydocstyle", +-- ["pylint"] = "pylint", +-- ["revive"] = "revive", +-- ["rstcheck"] = "rstcheck", +-- ["rubocop"] = "rubocop", +-- ["ruff"] = "ruff", +-- ["selene"] = "selene", +-- ["shellcheck"] = "shellcheck", +-- ["sqlfluff"] = "sqlfluff", +-- ["standardrb"] = "standardrb", +-- ["stylelint"] = "stylelint", +-- ["solhint"] = "solhint", +-- ["tflint"] = "tflint", +-- ["tfsec"] = "tfsec", +-- ["trivy"] = "trivy", +-- ["vale"] = "vale", +-- ["vint"] = "vint", +-- ["vulture"] = "vulture", +-- ["yamllint"] = "yamllint", +-- } +-- +-- -- add new mapping filetype +-- local addnew = { +-- ["typescriptreact"] = "eslint_d", +-- ["javascriptreact"] = "eslint_d", +-- ["javascript.jsx"] = "eslint_d", +-- ["typescript.tsx"] = "eslint_d", +-- ["vue"] = "eslint_d", +-- ["sevelte"] = "eslint_d", +-- ["astro"] = "eslint_d", +-- } +-- +-- local ignore = { +-- ["php"] = "tlint", +-- } +-- +-- -- local listtest = {} +-- for _, pkg in pairs(mason_reg.get_installed_packages()) do +-- for _, type in pairs(pkg.spec.categories) do +-- -- only act upon a Linter +-- if type == "Linter" then +-- -- finally add the linter to it's compatible filetype(s) +-- for _, ft in pairs(pkg.spec.languages) do +-- local ftl = string.lower(ft) +-- local ready = mason_reg.get_package(pkg.spec.name):is_installed() +-- if ready then +-- if keymap[ftl] ~= nil then +-- ftl = keymap[ftl] +-- end +-- +-- -- if substring(pkg.spec.name, "eslint") then +-- -- table.insert(listtest, ftl) +-- -- end +-- +-- if name_map[pkg.spec.name] ~= nil then +-- pkg.spec.name = name_map[pkg.spec.name] +-- end +-- +-- -- add new mapping language +-- for key, value in pairs(addnew) do +-- if value == pkg.spec.name then +-- opts.linters_by_ft[key] = opts.linters_by_ft[key] or {} +-- table.insert(opts.linters_by_ft[key], pkg.spec.name) +-- end +-- end +-- +-- if ignore[ftl] ~= pkg.spec.name then +-- opts.linters_by_ft[ftl] = opts.linters_by_ft[ftl] or {} +-- table.insert(opts.linters_by_ft[ftl], pkg.spec.name) +-- end +-- end +-- end +-- end +-- end +-- end +-- -- print(table.concat(listtest, ",")) +-- end, +-- config = function(_, opts) +-- require("lint").linters_by_ft = opts.linters_by_ft +-- end, +-- } +-- end return M