-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
feat: add spectral #530
feat: add spectral #530
Conversation
a6e6a8e
to
16317d8
Compare
Thank you so much, I was about to create a PR for this. A few checks before merging this PR.
Edit: .spectral.yaml should allow for spectral to just work on a file, with the file name as the command argument: Edit #2: I've noticed that vscode extension also have issues with allowing custom npm packages and suggested a workaround we can use here. stoplightio/vscode-spectral#214 |
Thanks for the feedback @SirAppSec! I don't think having specific logic for dependency issues is in scope for this plugin. We simply want to execute the linter as it is configured on the users system. I will build some basic error handling when I find the time, because right now there is no way of knowing whether the linter errored, which is pretty confusing. I would also like to throw an error when spectral is not in PATH. Your point about |
I removed the I also improved error handling so users get notified if no ruleset was found ( The case that Spectral can't be found on PATH is already handled by the plugin itself, so nothing to do here. @SirAppSec: Please feel free to take another look and give feedback 🙂 |
lua/lint/linters/spectral.lua
Outdated
-- attempt to decode linter result | ||
local success, result = pcall(vim.json.decode, output) | ||
if not success then | ||
vim.notify("Spectral exited with an error:\n" .. output, vim.log.levels.ERROR) | ||
return {} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- attempt to decode linter result | |
local success, result = pcall(vim.json.decode, output) | |
if not success then | |
vim.notify("Spectral exited with an error:\n" .. output, vim.log.levels.ERROR) | |
return {} | |
end | |
result = vim.json.decode(output) |
You can just let it fail, there is default error handling:
Lines 143 to 155 in 03b1fc5
local ok, diagnostics = pcall(parse, output, bufnr, linter_cwd) | |
if not ok then | |
local err = diagnostics | |
diagnostics = { | |
{ | |
bufnr = bufnr, | |
lnum = 0, | |
col = 0, | |
message = string.format(parse_failure_msg, err, output), | |
severity = vim.diagnostic.severity.ERROR | |
} | |
} | |
end |
Could you address the suggestion? |
@mfussenegger Sorry it took so long. I addressed your suggestion and rebased the branch. |
Hi @mfussenegger,
thanks for this great plugin.
I would like to add the Spectral linter for OpenAPI specifications.
There is a slight problem in that the linter takes a required parameter
--ruleset
that takes either a file path or a URL.Without this parameter, the linter will error out.
I have implemented it in a way, where the user would have to do something like this, which is a bit awkward 😄
Another approach would be to not specify the ruleset parameter by default, let the linter error and let the user figure out how to override the linters
args
. This is also pretty inconvenient.I would appreciate your feedback on which of the options you would prefer, or if you maybe have a better idea.
I could also contribute some better documentation so users would know how to configure this specific linter.
If it's not a good fit for the project because of this constraint, I obviously understand.