-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support for checkstyle plugin java. #50
Comments
Just took a quick look, it doesn't seem that checkstyle has a widely used cli interface. |
You can actually install checkstyle in ubuntu using |
Other way to run it would probably be |
Sure then I guess pr is welcome. Feel free to ask any questions :) |
I was going to implement this but my only doubt is about how to parse messages from the output. Checkstyle support xml and plain text and does not support json. So I cannot use vim.json to parse it. |
The output looks something of this sort. And I have to parse the ones in between. |
It's possible to use regex guard-collection/lua/guard-collection/linter/clang-tidy.lua Lines 1 to 16 in 9530991
Maybe it's possible to use some flags to silent some of the non-diagnostic output |
Ok. I reduced it to less output using
The log looks something like this. But it still has few redundant lines at the end. Do you have any idea on how can I get around these. Like is the regex going to ignore lines if they dont match the regex exp? |
Maybe you can try to match the guard-collection/lua/guard-collection/linter/codespell.lua Lines 1 to 20 in 716d7ee
|
@xiaoshihou514 sorry for this ping but I wanted you to take a look at this configuration for checkstyle and let me know if everything is right since even if I call ft("java"):lint({
cmd = "checkstyle",
args = {
"-c",
"sun_checks.xml",
},
fname = true,
parse = lint.from_regex({
source = "checkstyle",
regex = "%[(%w+)%]%s+.-:(%d+):?(%d*):%s+(.-)%s+%[(.-)%]",
groups = { "severity", "lnum", "col", "message", "code" },
severities = {
ERROR = lint.severities.error,
WARN = lint.severities.warning,
INFO = lint.severities.info,
DEBUG = lint.severities.style,
},
}),
}) I verified the working of the regex and it works well. So, regex is not the issue afaik. I also had one more doubt, like in few linter logs, there is no column number, so the above regex returns empty column number. For reference this is the log of checkstyle
|
I will just put print statements inside guard _ツ_/ Not ideal, but then again most formatters and linters aren't that complicated... I think a nil column number is fine? As for none matching lines I need to check the source, I think they are skipped. |
Ok. I think I found out what the issue is. The thing is that #data is returning 0 even though this is the content of data in this line {
code = 9,
signal = 0,
stderr = "Checkstyle ends with 9 errors.\n",
stdout = "Starting audit...\n[ERROR] /home/zeltron/git/concurrency/java-platf
orm/src/main/java/com/fibonacci/App.java:1: Missing package-info.java file. [Ja
vadocPackage]\n[ERROR] /home/zeltron/git/concurrency/java-platform/src/main/jav
a/com/fibonacci/App.java:12:1: Utility classes should not have a public or defa
ult constructor. [HideUtilityClassConstructor]\n[ERROR] /home/zeltron/git/concu
rrency/java-platform/src/main/java/com/fibonacci/App.java:13:30: Parameter n sh
ould be final. [FinalParameters]\n[ERROR] /home/zeltron/git/concurrency/java-pl
atform/src/main/java/com/fibonacci/App.java:35:27: Parameter args should be fin
al. [FinalParameters]\n[ERROR] /home/zeltron/git/concurrency/java-platform/src/
main/java/com/fibonacci/App.java:36:65: '8081' is a magic number. [MagicNumber]
\n[ERROR] /home/zeltron/git/concurrency/java-platform/src/main/java/com/fibonac
ci/App.java:40: Line is longer than 80 characters (found 89). [LineLength]\n[ER
ROR] /home/zeltron/git/concurrency/java-platform/src/main/java/com/fibonacci/Ap
p.java:46: Line is longer than 80 characters (found 100). [LineLength]\n[ERROR]
/home/zeltron/git/concurrency/java-platform/src/main/java/com/fibonacci/App.ja
va:47:42: '400' is a magic number. [MagicNumber]\n[ERROR] /home/zeltron/git/con
currency/java-platform/src/main/java/com/fibonacci/App.java:51:42: '400' is a m
agic number. [MagicNumber]\nAudit done.\n"
} |
@xiaoshihou514, I think this part of the code is the issue |
Looks fishy... Will take a look tomorrow. |
Ahh I see what's happening, You will have to override the default spawn function: https://github.com/nvimdev/guard.nvim/blob/main/ADVANCED.md#custom-logic-with-linters Seems like error reporting is not there for linters yet, will add it with event pr |
Hi! Is it possible to add checkstyle linter support in guard-collection.
The text was updated successfully, but these errors were encountered: