Skip to content

Commit

Permalink
feat(nvim): add nvim-lint with rubocop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andreaswachowski committed Sep 27, 2023
1 parent cb09435 commit a025dcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"mason.nvim": { "branch": "main", "commit": "d66c60e17dd6fd8165194b1d14d21f7eb2c1697a" },
"neodev.nvim": { "branch": "main", "commit": "e683583f8ba2f9dbbc4539889cbbdbfc5afb5fb2" },
"nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" },
"nvim-lint": { "branch": "master", "commit": "67f74e630a84ecfa73a82783c487bdedd8cecdc3" },
"nvim-lspconfig": { "branch": "master", "commit": "ede4114e1fd41acb121c70a27e1b026ac68c42d6" },
"nvim-surround": { "branch": "main", "commit": "0d6882635817a2677749a330127d12ac30a4f3c8" },
"nvim-treesitter": { "branch": "master", "commit": "b5873bacb4ce44e0aac313abb28bb72e67fc9a53" },
Expand All @@ -28,4 +29,4 @@
"vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" },
"which-key.nvim": { "branch": "main", "commit": "7ccf476ebe0445a741b64e36c78a682c1c6118b7" },
"yadm-git.vim": { "branch": "master", "commit": "dbf067f99ccfc000659dfef846230148ee22e388" }
}
}
18 changes: 18 additions & 0 deletions .config/nvim/lua/plugins/nvim-lint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
return {
"mfussenegger/nvim-lint",
config = function()
local rubocop = require('lint').linters.rubocop
rubocop.cmd = 'bundle'
rubocop.args = { 'exec', 'rubocop', '--format', 'json', '--force-exclusion' }
-- rubocop.stdin = true
require('lint').linters_by_ft = {
ruby = {
"rubocop"
}
}
vim.api.nvim_create_autocmd(
{ "BufWritePost" },
{ callback = function() require("lint").try_lint() end, }
)
end
}

0 comments on commit a025dcb

Please sign in to comment.