Skip to content

Don't enable shellcheck linting by default #999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zeioth opened this issue Oct 15, 2023 · 3 comments
Closed

Don't enable shellcheck linting by default #999

Zeioth opened this issue Oct 15, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Zeioth
Copy link

Zeioth commented Oct 15, 2023

What is the problem this feature will solve?

On neovim, when installing bash-language-server along with shellcheck, this triggers linting two times.

What is the feature you are proposing to solve the problem?

Make shellcheck linting disabled by default, and opt-in. As linting is the responsability of a linter, not the responsability of a lsp server.

Screenshot

screenshot_2023-10-15_16-56-14_110873179

@Zeioth Zeioth added the enhancement New feature or request label Oct 15, 2023
@Zeioth Zeioth closed this as completed Oct 15, 2023
@Zeioth Zeioth reopened this Oct 15, 2023
@Zeioth Zeioth changed the title Don't enable shcheck linting by default Don't enable shellcheck linting by default Oct 15, 2023
@Zeioth
Copy link
Author

Zeioth commented Oct 15, 2023

Ok after further research I managed to disable it with

local lsp_opts = {}
if server_name == "bashls" then -- by default disable shellcheck
  lsp_opts.settings = { bashIde = { shellcheckPath = "" } }
end

And while that keep the lsp capabilities, it disables the bash-language-server code actions for code fixes, which I find super valuable. So I'm closing this.

@Zeioth Zeioth closed this as completed Oct 15, 2023
@Zeioth
Copy link
Author

Zeioth commented Oct 15, 2023

In case someone is interested, this is how I made compatilbe bash-language-server and shellcheck on my neovim config:

null-ls

--  null-ls [lsp code formatting]
--  https://github.com/nvimtools/none-ls.nvim
{
  "nvimtools/none-ls.nvim",
  dependencies = {
    {
      "jay-babu/mason-null-ls.nvim",
      cmd = { "NullLsInstall", "NullLsUninstall" },
      opts = { handlers = {} },
    },
  },
  event = "BufEnter",
  opts = function()
    local nls = require "null-ls"
    return {
      sources = {
        -- You can customize your formatters here.
        nls.builtins.formatting.beautysh.with {
          command = "beautysh",
          args = { "--indent-size=2", "$FILENAME" },
        },
        -- TODO: Disable the next feature once this has been merged.
        -- https://github.com/bash-lsp/bash-language-server/issues/933
        nls.builtins.code_actions.shellcheck,
        nls.builtins.diagnostics.shellcheck.with { diagnostics_format = "" },
      },
      on_attach = require("base.utils.lsp").on_attach,
    }
  end,
  config = function(_, opts)
    local nls = require "null-ls"
    nls.setup(opts)

    -- When running :LspStart, ensure null-ls starts too
    vim.api.nvim_create_autocmd({ "LspAttach" }, {
      desc = "Ensure null-ls run its sources a lsp client starts",
      callback = function()
        pcall(function() require("null-ls").enable({}) end)
      end,
    })

  end
},

LSP config

if server_name == "bashls" then -- by default use mason shellcheck path
  lsp_opts.settings = { bashIde = { shellcheckPath = vim.fn.stdpath "data" .. "/mason/bin/shellcheck" } }
end

This way bash-language-server has all its normal capabilities and aditionally:

  • Mason install shellcheck for us. (to eliminate external dependencies)
  • Null ls disable diagnostics, but enable code actions. (to prevent double diagnostics + adding code actions for silencing rules)

Screenshot

screenshot_2023-10-16_01-48-35_133417388

@adoyle-h
Copy link

adoyle-h commented Oct 3, 2024

@Zeioth nls.builtins.code_actions.shellcheck shellcheck is not found in none-ls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants