mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.88k stars 198 forks source link

rubocop is throwing an error #336

Open otavioschwanck opened 1 year ago

otavioschwanck commented 1 year ago

Using

vim.api.nvim_create_autocmd({ "BufWritePost", "InsertLeave", "TextChanged" }, { callback = function() require("lint").try_lint() end, })

i debugged the rubocop.lua, the output variable on InsertLeave / TextChanged is "", only saving works. I have added the stdin function:

local severity_map = {
  ['fatal'] = vim.diagnostic.severity.ERROR,
  ['error'] = vim.diagnostic.severity.ERROR,
  ['warning'] = vim.diagnostic.severity.WARN,
  ['convention'] = vim.diagnostic.severity.HINT,
  ['refactor'] = vim.diagnostic.severity.INFO,
  ['info'] = vim.diagnostic.severity.INFO,
}

return {
  cmd = 'rubocop',
  stdin = true,
  args = { '--format', 'json', '--force-exclusion', '--stdin'},
  ignore_exitcode = true,
  parser = function(output)
    local diagnostics = {}

    local decoded = vim.json.decode(output)

    if not decoded.files[1] then
      return diagnostics
    end

    local offences = decoded.files[1].offenses

    for _, off in pairs(offences) do
      table.insert(diagnostics, {
        source = 'rubocop',
        lnum = off.location.start_line - 1,
        col = off.location.start_column - 1,
        end_lnum = off.location.last_line - 1,
        end_col = off.location.last_column,
        severity = severity_map[off.severity],
        message = off.message,
        code = off.cop_name
      })
    end

    return diagnostics
  end,
}

The error:

image

Using guard.nvim, the diagnostics works using the same cmd + args (always returns the output).

After fixing this (probably is not waiting enough for the diagnostics or something like that), i will make a PR to add the bundle_rubocop to the config (uses bundle to run rubocop installed on project instead of running from the shell), like i did on guard:

https://github.com/nvimdev/guard.nvim/blob/main/lua/guard/tools/linter/rubocop.lua

kjvdven commented 5 months ago

When I add Rubocop as a linter for ruby / rails, nvim becomes really sluggish taking several seconds to save the file and nvim becomes unresponsive.

Can this be related to this issue?

fernandoaleman commented 2 months ago

When I add Rubocop as a linter for ruby / rails, nvim becomes really sluggish taking several seconds to save the file and nvim becomes unresponsive.

Can this be related to this issue?

@kjvdven I seem to be having the same issue.