Skip to content
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

GoLint always runs against cwd, rather than the file that's open #1375

Closed
arp242 opened this issue Jul 24, 2017 · 6 comments
Closed

GoLint always runs against cwd, rather than the file that's open #1375

arp242 opened this issue Jul 24, 2017 · 6 comments

Comments

@arp242
Copy link
Contributor

arp242 commented Jul 24, 2017

  1. cd gopkg
  2. Open subpkg/file.go
  3. Run :GoLint
  4. :GoLint is run against the gopkg package rather than the subpkg package or file.go file.

I think it should run against either the subpkg package or file.go file. This is how e.g. :GoMetaLinter behaves.

I can make a PR if you agree that this is how it ought to behave @fatih

@fatih
Copy link
Owner

fatih commented Jul 24, 2017

Hi @Carpetsmoker

This is because GoLint works like that by default:

	golint [flags] # runs on package in current directory

That's also how it's described in our documentation. Don't want to much change the behaviour of the tools. GoMetaLinter works on a single files because of the number of linters it has, so it makes sense for it. We can later discuss it again if it's something worth tackling it.

@fatih fatih closed this as completed Jul 24, 2017
@arp242
Copy link
Contributor Author

arp242 commented Jul 24, 2017

Alright. Personally I think this is very confusing and unexpected behaviour though. I was very confused when it said there were no errors even though I saw a clear lint error in my buffer...

@arp242
Copy link
Contributor Author

arp242 commented Jul 24, 2017

Also :GoVet behaves different as well:

Run go vet for the directory under your current file.

Most commands run for the current file/buffer or the package the file belongs to. I'm not sure how many other commands there are that use the current directory?

@fatih
Copy link
Owner

fatih commented Jul 24, 2017

I just thought that each command should exactly work the same when you run it inside the terminal in that files' particular directory. Do you think we should change the default behaviors ?

@arp242
Copy link
Contributor Author

arp242 commented Jul 24, 2017

I did some testing, and this is how the commands that operate on files or package behave:

Command cmdline behaviour vim-go behaviour
:GoLint Package in cwd Same
:GoFmt stdin/file Same
:GoImports stdin/file Same
:GoVet Package in cwd Package of open buffer
:GoErrCheck Package in cwd Package of open buffer
:GoRun Explicit pkg/file Package of open buffer
:GoBuild Package in cwd Package of open buffer
:GoGenerate Package in cwd Didn't test, as I can't be bothered to figure out how to use this feature
:GoInstall Package in cwd Package of open buffer
:GoTest Package in cwd Package of open buffer
:GoFiles Package in cwd Package of open buffer
:GoDeps Package in cwd Package of open buffer
:GoMetaLinter Package in cwd Package of open buffer

Unless I've messed up my testing here, :GoLint seems to be the only command that operates on the current working directory. All other vim-go commands operate on either the file that's open or the package that the file belongs to, irrespective of how the command-line tools operate.

@fatih fatih reopened this Jul 25, 2017
@fatih
Copy link
Owner

fatih commented Jul 25, 2017

This seems something worth tackling. Thanks for the research Martin much appreciated. I believe the behavior for :GoLint was based on a file and then later changed to the directory itself (I might done it myself). Having a general policy that each command is responsible for the package of open buffer is a better choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants