Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ This linter plugin for [SublimeLinter](https://github.com/SublimeLinter) provide

## Installation

- Install SublimeLinter 3 from [here](https://packagecontrol.io/packages/SublimeLinter)
- Install SublimeLinter from [here](https://packagecontrol.io/packages/SublimeLinter)
- Install SublimeLinter-golangcilint from [here](https://packagecontrol.io/packages/SublimeLinter-golangcilint)
- Install the `golangci-lint` helper from [here](https://github.com/golangci/golangci-lint#install)
- Install the `golangci-lint` helper from [here](https://golangci-lint.run/welcome/install/#local-installation)

![screenshot](screenshot.png)

## Configuration

In order for `golangci-lint` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. Before going any further, please read and follow the steps in [Finding a linter executable](http://sublimelinter.readthedocs.org/en/latest/troubleshooting.html#finding-a-linter-executable) through “Validating your PATH” in the documentation. Once you have installed `golangci-lint`, you can proceed to install the plugin if it is not yet installed.
For `golangci-lint` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. Before going any further, please read and follow the steps in [Finding a linter executable](https://sublimelinter.readthedocs.io/en/stable/troubleshooting.html#finding-a-linter-executable) through “Validating your PATH” in the documentation. Once you have installed `golangci-lint`, you can proceed to install the plugin if it is not yet installed.

Due to the way that golangci-lint works, the linter will only run when saving a file, even if `lint_mode` is set to “background”.
By default, the plugin expects `golangci-lint` version 2. To configure the plugin for `golangci-lint` version 1, set
the `v1` setting to `true`:

```json
"golangcilint": {
"v1": true
}
```

Due to the way that `golangci-lint` works, the linter will only run when saving a file, even if `lint_mode` is set to “background”.

## Plugin installation

Expand Down
6 changes: 4 additions & 2 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@


class GolangCILint(Linter):
cmd = 'golangci-lint run ${args} --out-format tab ${file_path}'
def cmd(self):
if self.settings.get("v1", False):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaste This is still too magical. Do we need to run golangci-lint version somehow and regex the version out of what's returned?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, that would be just a manual setting. We would need to add that to the README and then the release notes.

Of course it would be possible to automate this, let me sketch that out. Let's see if I get that just out of my head:

import shutil
from SublimeLinter.lint import util
# first resolve the executable
if binary:= shutil.which("golangci"):
    stdout: str = util.check_output([binary, "<whatever arg it takes to return the version>"])
    # parse stdout with a regex or simpler if stdout.startswith("1.")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaste Thanks! It occurred to me only later that we were creating a new setting. I actually like the idea of making it just a setting. Very light weight and robust.

I've pushed up some more changes. What do you think now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😄

return 'golangci-lint run ${args} --out-format tab ${file_path}'
return 'golangci-lint run ${args} --output.tab.path stdout ${file_path}'
tempfile_suffix = '-'
# Column reporting is optional and not provided by all linters.
# Issues reported by the 'typecheck' linter are treated as errors,
Expand All @@ -13,5 +16,4 @@ class GolangCILint(Linter):
default_type = WARNING
defaults = {
'selector': 'source.go',
'args': '--fast'
}