Ale: gosimple and staticcheck linter don't find types defined in other files in the same package.

Created on 15 Sep 2017  Â·  7Comments  Â·  Source: dense-analysis/ale


 Current Filetype: go
Available Linters: ['go build', 'gofmt', 'golint', 'gometalinter', 'gosimple', 'go vet', 'staticcheck']
  Enabled Linters: ['gosimple']
 Linter Variables:

 Global Variables:

let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%s'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'always'
let g:ale_linter_aliases = {}
let g:ale_linters = {'go': ['gosimple']}
let g:ale_open_list = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_offset = 1000000
let g:ale_sign_warning = 'âš '
let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK']
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) gosimple
(started) ['bash', '-c', 'gosimple ''/tmp/nvimuKWnOb/4/raft.go''']
(started) ['bash', '-c', 'gosimple ''/tmp/nvimuKWnOb/7/raft.go''']
(started) ['bash', '-c', 'gosimple ''/tmp/nvimuKWnOb/8/raft.go''']
(started) ['bash', '-c', 'gosimple ''/tmp/nvimuKWnOb/10/raft.go''']
(finished - exit code 1) ['bash', '-c', 'gosimple ''/tmp/nvimuKWnOb/11/raft.go''']

<<<OUTPUT STARTS>>>
/tmp/nvimuKWnOb/11/raft.go:25:11: undeclared name: remoteKVDatabase
/tmp/nvimuKWnOb/11/raft.go:33:14: undeclared name: remoteKVConnection
/tmp/nvimuKWnOb/11/raft.go:125:4: undeclared name: KVDatabase
/tmp/nvimuKWnOb/11/raft.go:150:65: undeclared name: remoteKVConnection
/tmp/nvimuKWnOb/11/raft.go:179:51: undeclared name: remoteKVConnection
/tmp/nvimuKWnOb/11/raft.go:192:49: undeclared name: remoteKVConnection
/tmp/nvimuKWnOb/11/raft.go:279:56: undeclared name: KVTable
/tmp/nvimuKWnOb/11/raft.go:289:42: undeclared name: Row
/tmp/nvimuKWnOb/11/raft.go:313:42: undeclared name: SeekAt
/tmp/nvimuKWnOb/11/raft.go:313:99: undeclared name: Row
/tmp/nvimuKWnOb/11/raft.go:326:51: undeclared name: SelectArgs
/tmp/nvimuKWnOb/11/raft.go:326:89: undeclared name: Row
/tmp/nvimuKWnOb/11/raft.go:43:72: undeclared name: KVManager
/tmp/nvimuKWnOb/11/raft.go:117:30: invalid operation: m.conn (variable of type *invalid type) has no field or method conn
/tmp/nvimuKWnOb/11/raft.go:128:18: undeclared name: newRemoteKVDatabase
/tmp/nvimuKWnOb/11/raft.go:155:15: undeclared name: newRemoteKVConnection
/tmp/nvimuKWnOb/11/raft.go:195:12: undeclared name: remoteKVConnection
/tmp/nvimuKWnOb/11/raft.go:280:9: undeclared name: newKVTable
/tmp/nvimuKWnOb/11/raft.go:285:10: invalid operation: db.remote (variable of type *invalid type) has no field or method Put
/tmp/nvimuKWnOb/11/raft.go:291:10: invalid operation: db.remote (variable of type *invalid type) has no field or method PutMany
/tmp/nvimuKWnOb/11/raft.go:300:14: invalid operation: db.remote (variable of type *invalid type) has no field or method Get
/tmp/nvimuKWnOb/11/raft.go:309:10: invalid operation: db.remote (variable of type *invalid type) has no field or method Delete
/tmp/nvimuKWnOb/11/raft.go:315:13: undeclared name: Row
/tmp/nvimuKWnOb/11/raft.go:319:15: invalid operation: db.remote (variable of type *invalid type) has no field or method Select
/tmp/nvimuKWnOb/11/raft.go:328:20: undeclared name: Row
/tmp/nvimuKWnOb/11/raft.go:332:20: invalid operation: db.remote (variable of type *invalid type) has no field or method BatchSelect
/tmp/nvimuKWnOb/11/raft.go:340:2: invalid operation: db.remote (variable of type *invalid type) has no field or method Close
/tmp/nvimuKWnOb/11/raft.go:345:10: invalid operation: db.remote (variable of type *invalid type) has no field or method FlushAndClose
/tmp/nvimuKWnOb/11/raft.go:353:14: invalid operation: db.remote (variable of type *invalid type) has no field or method GetProperty
/tmp/nvimuKWnOb/11/raft.go:60:34: invalid operation: m.conn (variable of type *invalid type) has no field or method conn
couldn't load packages due to errors: adhoc
<<<OUTPUT ENDS>>>

I get the same output when I only run the gosimple command on the single file I'm in. Running it on the full directory works fine though. Is there a way to define the linter in such a way that the temporary directory with the new file contains the other files in the directory as well?

bug

Most helpful comment

Now gosimple and gotype check whole packages. Now we can wait for someone to make the 10th tool for checking Go programs until it also has the same problem, like goextrasimple.

All 7 comments

There are two ways to handle this.

  1. Pass some information to the program to tell it where the files are.
  2. Just use the real file and lose the ability to check for errors while you type.

We should pick whatever is appropriate for these linters. I've noticed lots of issues with the Go tools.

Related: https://github.com/dominikh/go-tools/issues/81

There the authors claim that it works "just like go build", and yes, if you pass a single file as go build <filename> it will fail with the same issue... But in ALE go build has no issues with types being declared in different files, it works absolutely fine. How is it working, is it really dependent on the files being saved, or ALE provides some information for go build on how to discover other files?

go build use the files on disk, so I'll make gosimple and staticcheck do the same. You can't check for errors while you type with those tools, because the tools don't support it.

Done!

Somehow the problem is still not fixed for me, not sure if I'm doing something wrong. @JelteF what about you?

Okay, please submit a pull request to fix the issue if you can figure it out. I don't write Go myself.

You might want to look at the gobuild linter, which sets GOPATH and changes directory.

Now gosimple and gotype check whole packages. Now we can wait for someone to make the 10th tool for checking Go programs until it also has the same problem, like goextrasimple.

Was this page helpful?
0 / 5 - 0 ratings