Skip to content
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

rubocop is throwing an error #336

Open
otavioschwanck opened this issue Aug 2, 2023 · 2 comments
Open

rubocop is throwing an error #336

otavioschwanck opened this issue Aug 2, 2023 · 2 comments
Labels
needs: contribution Contributions are welcome

Comments

@otavioschwanck
Copy link

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

andreaswachowski added a commit to andreaswachowski/dotfiles that referenced this issue Sep 27, 2023
Basic setup from [^1]. Basic bundle integration found in [^3].

Open issues:
- Linting fails when rubocop is not available in the bundle.
  One can provide a function for the linter[^2] and should be able to
  use either the bundled rubocop, or a global rubocop as fallback.
- When rubocop itself fails (with error code 2), like when it sees an
  unrecognized cop in .rubocop.yml, this is unnoticed during editing.
- Make rubocop run on BufReadPost, InsertLeave, and TextChanged events.
  This is mentioned in mfussenegger/nvim-lint#336

[^1]: dietrichm/dotfiles#138
[^2]: mfussenegger/nvim-lint#18
[^3]: https://github.com/pfeiferj/dotfiles/blob/9fe44801e52590610d2090f2c03df6fbb31b6f57/dot_config/nvim/lua/plugins/lint.lua
@kjvdven
Copy link

kjvdven commented Apr 12, 2024

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
Copy link

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.

@mfussenegger mfussenegger added the needs: contribution Contributions are welcome label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: contribution Contributions are welcome
Projects
None yet
Development

No branches or pull requests

4 participants