-
Notifications
You must be signed in to change notification settings - Fork 8
Simplify the 'GolangCILint' class #3
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
Conversation
When using a recent version of 'golangci-lint', the generated output is predictable enough to be parsed by a regex instead of converting JSON output. This simplifies the code needed for linting considerably and removes the need of a temporary file. Furthermore, by using the 'filename' capture group introduced in SublimeLinter 4.13, a lot of false positives are fixed.
|
Good job! What sour people who have an older version of golangci-lint? |
|
I’ll run some tests during the day. I think @nfnt did a very good job at simplifying the code, but I’m a worried this will break the functionality for people who haven’t upgraded to the latest version of Version 1.19.1 was released just yesterday that’s not enough time to let people upgrade, and that makes me hesitant to merge these changes soon; @nfnt when you tested your code with older versions of |
|
Let me check with older versions. I was on 1.18 when doing the first tests and this worked as well. But it would be great to have a good guideline on which versions work and which don't. I'll run some more tests. |
|
Just tested with |
|
Am I reading the release page wrong? https://github.com/golangci/golangci-lint/releases I can see that version 1.9.0 was released four days ago. Where did you get July 2018 from? As a reference, I am still using 1.17.1 which was released on June. Anyway, regardless of the correctness of the code with respect to the latest version of golangci-lint available, we should at least offer a fallback in case people are using an older version. Let’s plan something that works for you and also avoids complaints from the community. Edit: wait, I just re-read your comment, you said 1.9 but I thought you were talking about 1.19; I apologize. If your test is correct then I guess we can release your changes soon, let me take another look and if everything is okay I’ll merge and release a new version of the plugin with your contributions. |
|
This is the |
|
@nfnt here’s a few things I noticed:
I personally have an aversion for regular expressions, but overall your code works well and is definitely simpler than the previous one. I hope we can address at least the second point in my comment (background linting not working) and then we will be ready to release a new version. |
|
Good point regarding the output format. The regex is easy to adapt to |
|
Fwiw the group has the name 'code' not 'linter'. The linter name is not under control of plugins but the backend. |
This also sets the 'code' capture group.
|
I changed the output format to |
|
Good job @nfnt on converting the command and regex. Regarding the addition of Here is an example where you can see this problem: https://cixtor.com/s3/example.zip |
|
Interesting, all my projects are using Go modules and I'm not seeing these issues. I'll take a look. |
|
IIUC, by setting |
|
That’s strange. Why am I seeing this warning? 🤔 Can you please try the following:
|
|
Very interesting! I'm seeing a warning here as well. Don't see this warning when running |
This reverts commit 73ab429.
|
@nfnt You actually just run a different command if Likewise Note that the latter opens stdin and sends the buffer content to the process/linter. This is not okay if the linter does not read from stdin as well bc it will result in One solution is to set the |
|
|
|
Last paragraph in my previous comment ☝️ |
|
I'm not sure, @cixtor can probably answer this more clearly. It looks like some of the code that I'm removing was there to add background mode support for this file-only linter. |
Currently the linter supports background lint mode, however, it does it in a non-performant way —by copying the content of the project into a temporary directory— because the content of the buffer needs to be in the same directory as the other files, otherwise Slowness is not really a problem, However, the README explains a limitation in the current implementation. To work in background mode, the linter needs to copy the project to a different folder, but many Go projects are considerably large. If the linter aborts the operation if it detects more than The linter will also abort the operation if it detects the project is using a canonical import path because in that case copying the content of the project to a temporary folder will immediately fail because the file path is different. And after saying that I realized that the current implementation doesn’t supports Go Modules in “background” lint mode because it is not copying the Anyway, the point is, the current implementation kind of supports background lint mode but only in relatively small projects. But even if we manage to fix that, there are other limitations imposed by Go itself, canonical import paths are just one of them. The only way this plugin works well is when lint mode is set to All of this is to say that the current code, while not perfect, has already been iterated several times to handle a handful of annoying edge cases. While the code proposed by @nfnt is interesting and clever, it takes us back to the very beginning where the edge cases are not handled and we have to start all over again testing and fixing bug reports. |
|
Hm, as I understand the code, we linted a directory and not a project (t.i. a folder recursively). Hard to believe someone has more than 1000 files in one directory but okay. The linter website says if we omit the last args it defaults to Not recursively should be faster, so if it returns sane results I would go for that. But if it's not reliable enough, I wouldn't confuse users and pick the slower one. Should this be configurable? Is it plausible that per project someone wants to include a specific folder always, e.g. |
Go packages can consist of multiple files in the same folder. Because constants, types, ... are shared between these files of a package, the whole folder must be linted to avoid false positives.
|
Thanks for the detailed explanations, I wasn't really aware how background-mode works under the hood. Did some test with enabled debug-logging and found a (IMO) good solution for file-only linting. Due to the way packages are working on Go, every file in |
|
That sounds good. Can you add a visible warning for users with |
|
SublimeLinter will choose the best mode applicable if background is set. Users don't have to change their settings for that. But sure a note that the plugin now only works on saved files bc they will notice that and wonder. |
|
Good point! Updated the |
|
Sorry for the long delay, I just checked and it seems to work okay. Although I was expecting an in-editor warning rather than a message in the README, but I guess people who are using this plugin are smart enough to look for answers in the repository if they notice the plugin is not doing anything, eventually they will find the warning in the README. Is this something we should take care of in this pull-request? Maybe not since this is probably due to the nature of the Go packages that I am hosting privately. It would be nice to have a visible warning about this. I only found the warning after inspecting the SublimeText console. I think I will add something later. I’ll test a bit more and merge then release in a few hours. |
|
Nice work guys! 🎉 |


When using a recent version of
golangci-lint(I tested withv1.19.1), the generated output ispredictable enough to be parsed by a regex instead of converting JSON output.
This simplifies the code needed for linting considerably and removes the need of
a temporary file. Furthermore, by using the
filenamecapture group introducedin SublimeLinter 4.13, a lot of false positives are fixed.