pikeman 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +21 -0
- data/CONTRIBUTING.md +15 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +27 -0
- data/LICENSE.txt +21 -0
- data/Makefile +39 -0
- data/README.md +85 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/pikeman +15 -0
- data/bin/setup +8 -0
- data/golint/golint.go +213 -0
- data/golint/import.go +309 -0
- data/golint/version.go +3 -0
- data/lib/pikeman.rb +34 -0
- data/lib/pikeman/version.rb +3 -0
- data/lint.go +1708 -0
- data/lint_test.go +317 -0
- data/misc/emacs/golint.el +54 -0
- data/misc/vim/ftplugin/go/lint.vim +31 -0
- data/pikeman.gemspec +28 -0
- data/testdata/4.go +38 -0
- data/testdata/5_test.go +17 -0
- data/testdata/blank-import-lib.go +39 -0
- data/testdata/blank-import-lib_test.go +25 -0
- data/testdata/blank-import-main.go +14 -0
- data/testdata/broken.go +9 -0
- data/testdata/common-methods.go +16 -0
- data/testdata/const-block.go +36 -0
- data/testdata/context.go +24 -0
- data/testdata/contextkeytypes.go +38 -0
- data/testdata/else-multi.go +18 -0
- data/testdata/else.go +23 -0
- data/testdata/error-return.go +43 -0
- data/testdata/errorf.go +40 -0
- data/testdata/errors.go +38 -0
- data/testdata/iferr.go +101 -0
- data/testdata/import-dot.go +8 -0
- data/testdata/inc.go +14 -0
- data/testdata/names.go +116 -0
- data/testdata/pkg-caps.go +4 -0
- data/testdata/pkg-doc1.go +3 -0
- data/testdata/pkg-doc2.go +5 -0
- data/testdata/pkg-doc3.go +7 -0
- data/testdata/pkg-doc4.go +7 -0
- data/testdata/pkg-doc5.go +9 -0
- data/testdata/pkg-main.go +5 -0
- data/testdata/range.go +43 -0
- data/testdata/receiver-names.go +49 -0
- data/testdata/sort.go +20 -0
- data/testdata/stutter.go +25 -0
- data/testdata/time.go +13 -0
- data/testdata/unexp-return.go +46 -0
- data/testdata/var-decl.go +86 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a49c667ba4a3471544800af686a17eebc5fad019
|
4
|
+
data.tar.gz: fe270b436382ff0bc2d150477ec2575e61de23e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85f330d4e73e55f5a883e5f77fdcc831f2de4026de83641365dbb0493cd9567cdbafd4f16c8ae7cb4fbaf40f45e831db7bb03a2a7c498225ee50b0a6577332ce
|
7
|
+
data.tar.gz: 577ba7f5d54a2807ba4d31196da854369c94d9eb69aedb7d863fc77ae7303bd8d51bf1785ae96239cb3127dcbe8d738b37fe20f921cb1d124db3e93ba3acd74e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: go
|
3
|
+
go:
|
4
|
+
- 1.8.x
|
5
|
+
- 1.9.x
|
6
|
+
- 1.10.x
|
7
|
+
- master
|
8
|
+
ruby:
|
9
|
+
- 2.3.3
|
10
|
+
before_install: gem install bundler -v 1.16.0
|
11
|
+
|
12
|
+
install:
|
13
|
+
- go get -t -v ./...
|
14
|
+
|
15
|
+
script:
|
16
|
+
- make test
|
17
|
+
|
18
|
+
matrix:
|
19
|
+
allow_failures:
|
20
|
+
- go: master
|
21
|
+
fast_finish: true
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Contributing to Golint
|
2
|
+
|
3
|
+
## Before filing an issue:
|
4
|
+
|
5
|
+
### Are you having trouble building golint?
|
6
|
+
|
7
|
+
Check you have the latest version of its dependencies. Run
|
8
|
+
```
|
9
|
+
go get -u github.com/golang/lint
|
10
|
+
```
|
11
|
+
If you still have problems, consider searching for existing issues before filing a new issue.
|
12
|
+
|
13
|
+
## Before sending a pull request:
|
14
|
+
|
15
|
+
Have you understood the purpose of golint? Make sure to carefully read `README`.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pikeman (0.1.0)
|
5
|
+
cli-kit
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
byebug (10.0.0)
|
11
|
+
cli-kit (3.0.0)
|
12
|
+
cli-ui (>= 1.1.0)
|
13
|
+
cli-ui (1.1.0)
|
14
|
+
coderay (1.1.2)
|
15
|
+
method_source (0.9.0)
|
16
|
+
minitest (5.11.3)
|
17
|
+
pry (0.11.3)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.9.0)
|
20
|
+
pry-byebug (3.6.0)
|
21
|
+
byebug (~> 10.0)
|
22
|
+
pry (~> 0.10)
|
23
|
+
rake (10.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
minitest (~> 5.0)
|
31
|
+
pikeman!
|
32
|
+
pry-byebug
|
33
|
+
rake (~> 10.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
1.16.0
|
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2013 The Go Authors. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are
|
5
|
+
met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above
|
10
|
+
copyright notice, this list of conditions and the following disclaimer
|
11
|
+
in the documentation and/or other materials provided with the
|
12
|
+
distribution.
|
13
|
+
* Neither the name of Google Inc. nor the names of its
|
14
|
+
contributors may be used to endorse or promote products derived from
|
15
|
+
this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Maxime Bedard
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
NAME=pikeman
|
2
|
+
GO_PACKAGE=github.com/maximebedard/pikeman
|
3
|
+
RUBY_MODULE=Pikeman
|
4
|
+
VERSION=$(shell cat VERSION)
|
5
|
+
GOFILES=$(shell find . -type f -name '*.go')
|
6
|
+
GEM=$(NAME)-$(VERSION).gem
|
7
|
+
|
8
|
+
.PHONY: all
|
9
|
+
|
10
|
+
default: release
|
11
|
+
release: $(GEM)
|
12
|
+
test: gotest rbtest
|
13
|
+
binaries: build/linux-amd64/pikeman build/darwin-amd64/pikeman
|
14
|
+
|
15
|
+
build/linux-amd64/pikeman: $(GOFILES) golint/version.go
|
16
|
+
GOOS=linux GOARCH=amd64 go build -o "$@" ./golint
|
17
|
+
|
18
|
+
build/darwin-amd64/pikeman: $(GOFILES) golint/version.go
|
19
|
+
GOOS=darwin GOARCH=amd64 go build -o "$@" ./golint
|
20
|
+
|
21
|
+
gotest:
|
22
|
+
go test -race -v ./...
|
23
|
+
|
24
|
+
rbtest:
|
25
|
+
bundle exec rake test
|
26
|
+
|
27
|
+
$(GEM): \
|
28
|
+
lib/$(NAME)/version.rb \
|
29
|
+
build/linux-amd64/pikeman \
|
30
|
+
build/darwin-amd64/pikeman
|
31
|
+
gem build pikeman.gemspec && gem push $@ && rm $@
|
32
|
+
|
33
|
+
golint/version.go: VERSION
|
34
|
+
mkdir -p $(@D)
|
35
|
+
echo 'package main\n\nconst VERSION string = "$(VERSION)"' > $@
|
36
|
+
|
37
|
+
lib/$(NAME)/version.rb: VERSION
|
38
|
+
mkdir -p $(@D)
|
39
|
+
echo 'module $(RUBY_MODULE)\n VERSION = "$(VERSION)"\nend' > $@
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
Golint is a linter for Go source code.
|
2
|
+
|
3
|
+
[](https://travis-ci.org/golang/lint)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Golint requires Go 1.6 or later.
|
8
|
+
|
9
|
+
go get -u golang.org/x/lint/golint
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Invoke `golint` with one or more filenames, directories, or packages named
|
14
|
+
by its import path. Golint uses the same
|
15
|
+
[import path syntax](https://golang.org/cmd/go/#hdr-Import_path_syntax) as
|
16
|
+
the `go` command and therefore
|
17
|
+
also supports relative import paths like `./...`. Additionally the `...`
|
18
|
+
wildcard can be used as suffix on relative and absolute file paths to recurse
|
19
|
+
into them.
|
20
|
+
|
21
|
+
The output of this tool is a list of suggestions in Vim quickfix format,
|
22
|
+
which is accepted by lots of different editors.
|
23
|
+
|
24
|
+
## Purpose
|
25
|
+
|
26
|
+
Golint differs from gofmt. Gofmt reformats Go source code, whereas
|
27
|
+
golint prints out style mistakes.
|
28
|
+
|
29
|
+
Golint differs from govet. Govet is concerned with correctness, whereas
|
30
|
+
golint is concerned with coding style. Golint is in use at Google, and it
|
31
|
+
seeks to match the accepted style of the open source Go project.
|
32
|
+
|
33
|
+
The suggestions made by golint are exactly that: suggestions.
|
34
|
+
Golint is not perfect, and has both false positives and false negatives.
|
35
|
+
Do not treat its output as a gold standard. We will not be adding pragmas
|
36
|
+
or other knobs to suppress specific warnings, so do not expect or require
|
37
|
+
code to be completely "lint-free".
|
38
|
+
In short, this tool is not, and will never be, trustworthy enough for its
|
39
|
+
suggestions to be enforced automatically, for example as part of a build process.
|
40
|
+
Golint makes suggestions for many of the mechanically checkable items listed in
|
41
|
+
[Effective Go](https://golang.org/doc/effective_go.html) and the
|
42
|
+
[CodeReviewComments wiki page](https://golang.org/wiki/CodeReviewComments).
|
43
|
+
|
44
|
+
## Scope
|
45
|
+
|
46
|
+
Golint is meant to carry out the stylistic conventions put forth in
|
47
|
+
[Effective Go](https://golang.org/doc/effective_go.html) and
|
48
|
+
[CodeReviewComments](https://golang.org/wiki/CodeReviewComments).
|
49
|
+
Changes that are not aligned with those documents will not be considered.
|
50
|
+
|
51
|
+
## Contributions
|
52
|
+
|
53
|
+
Contributions to this project are welcome provided they are [in scope](#scope),
|
54
|
+
though please send mail before starting work on anything major.
|
55
|
+
Contributors retain their copyright, so we need you to fill out
|
56
|
+
[a short form](https://developers.google.com/open-source/cla/individual)
|
57
|
+
before we can accept your contribution.
|
58
|
+
|
59
|
+
## Vim
|
60
|
+
|
61
|
+
Add this to your ~/.vimrc:
|
62
|
+
|
63
|
+
set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
|
64
|
+
|
65
|
+
If you have multiple entries in your GOPATH, replace `$GOPATH` with the right value.
|
66
|
+
|
67
|
+
Running `:Lint` will run golint on the current file and populate the quickfix list.
|
68
|
+
|
69
|
+
Optionally, add this to your `~/.vimrc` to automatically run `golint` on `:w`
|
70
|
+
|
71
|
+
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
|
72
|
+
|
73
|
+
|
74
|
+
## Emacs
|
75
|
+
|
76
|
+
Add this to your `.emacs` file:
|
77
|
+
|
78
|
+
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/golang/lint/misc/emacs"))
|
79
|
+
(require 'golint)
|
80
|
+
|
81
|
+
If you have multiple entries in your GOPATH, replace `$GOPATH` with the right value.
|
82
|
+
|
83
|
+
Running M-x golint will run golint on the current file.
|
84
|
+
|
85
|
+
For more usage, see [Compilation-Mode](http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pikeman"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/pikeman
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
platform = `uname -sm`
|
3
|
+
|
4
|
+
dir =
|
5
|
+
case platform
|
6
|
+
when /^Darwin/ ; "darwin-amd64"
|
7
|
+
when /^Linux.*64/ ; "linux-amd64"
|
8
|
+
else
|
9
|
+
abort "pikeman is not supported on your platform."
|
10
|
+
end
|
11
|
+
|
12
|
+
bindir = File.expand_path("../../build/#{dir}", __FILE__)
|
13
|
+
puts bindir
|
14
|
+
ENV["PATH"] = "#{bindir}:#{ENV["PATH"]}"
|
15
|
+
exec "pikeman", *ARGV
|
data/bin/setup
ADDED
data/golint/golint.go
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
// Copyright (c) 2013 The Go Authors. All rights reserved.
|
2
|
+
//
|
3
|
+
// Use of this source code is governed by a BSD-style
|
4
|
+
// license that can be found in the LICENSE file or at
|
5
|
+
// https://developers.google.com/open-source/licenses/bsd.
|
6
|
+
|
7
|
+
// golint lints the Go source files named on its command line.
|
8
|
+
package main
|
9
|
+
|
10
|
+
import (
|
11
|
+
"encoding/json"
|
12
|
+
"flag"
|
13
|
+
"fmt"
|
14
|
+
"go/build"
|
15
|
+
"io/ioutil"
|
16
|
+
"os"
|
17
|
+
"path/filepath"
|
18
|
+
"strings"
|
19
|
+
|
20
|
+
"golang.org/x/lint"
|
21
|
+
)
|
22
|
+
|
23
|
+
var (
|
24
|
+
minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it")
|
25
|
+
setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found")
|
26
|
+
formatterType = flag.String("format", "text", "set the format. Available: text, json.")
|
27
|
+
suggestions int
|
28
|
+
formatter problemFormatter
|
29
|
+
)
|
30
|
+
|
31
|
+
func usage() {
|
32
|
+
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
33
|
+
fmt.Fprintf(os.Stderr, "\tgolint [flags] # runs on package in current directory\n")
|
34
|
+
fmt.Fprintf(os.Stderr, "\tgolint [flags] [packages]\n")
|
35
|
+
fmt.Fprintf(os.Stderr, "\tgolint [flags] [directories] # where a '/...' suffix includes all sub-directories\n")
|
36
|
+
fmt.Fprintf(os.Stderr, "\tgolint [flags] [files] # all must belong to a single package\n")
|
37
|
+
fmt.Fprintf(os.Stderr, "Version: %s\n", VERSION)
|
38
|
+
fmt.Fprintf(os.Stderr, "Flags:\n")
|
39
|
+
flag.PrintDefaults()
|
40
|
+
}
|
41
|
+
|
42
|
+
func main() {
|
43
|
+
flag.Usage = usage
|
44
|
+
flag.Parse()
|
45
|
+
|
46
|
+
switch *formatterType {
|
47
|
+
case "json":
|
48
|
+
formatter = &jsonFormatter{}
|
49
|
+
default:
|
50
|
+
formatter = &textFormatter{}
|
51
|
+
}
|
52
|
+
|
53
|
+
if flag.NArg() == 0 {
|
54
|
+
lintDir(".")
|
55
|
+
} else {
|
56
|
+
// dirsRun, filesRun, and pkgsRun indicate whether golint is applied to
|
57
|
+
// directory, file or package targets. The distinction affects which
|
58
|
+
// checks are run. It is no valid to mix target types.
|
59
|
+
var dirsRun, filesRun, pkgsRun int
|
60
|
+
var args []string
|
61
|
+
for _, arg := range flag.Args() {
|
62
|
+
if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) {
|
63
|
+
dirsRun = 1
|
64
|
+
for _, dirname := range allPackagesInFS(arg) {
|
65
|
+
args = append(args, dirname)
|
66
|
+
}
|
67
|
+
} else if isDir(arg) {
|
68
|
+
dirsRun = 1
|
69
|
+
args = append(args, arg)
|
70
|
+
} else if exists(arg) {
|
71
|
+
filesRun = 1
|
72
|
+
args = append(args, arg)
|
73
|
+
} else {
|
74
|
+
pkgsRun = 1
|
75
|
+
args = append(args, arg)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
if dirsRun+filesRun+pkgsRun != 1 {
|
80
|
+
usage()
|
81
|
+
os.Exit(2)
|
82
|
+
}
|
83
|
+
switch {
|
84
|
+
case dirsRun == 1:
|
85
|
+
for _, dir := range args {
|
86
|
+
lintDir(dir)
|
87
|
+
}
|
88
|
+
case filesRun == 1:
|
89
|
+
lintFiles(args...)
|
90
|
+
case pkgsRun == 1:
|
91
|
+
for _, pkg := range importPaths(args) {
|
92
|
+
lintPackage(pkg)
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
if *setExitStatus && suggestions > 0 {
|
98
|
+
fmt.Fprintf(os.Stderr, "Found %d lint suggestions; failing.\n", suggestions)
|
99
|
+
os.Exit(1)
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
type textFormatter struct{}
|
104
|
+
|
105
|
+
func (tf *textFormatter) Write(p lint.Problem) {
|
106
|
+
fmt.Printf("%v: %s\n", p.Position, p.Text)
|
107
|
+
}
|
108
|
+
|
109
|
+
type problemFormatter interface {
|
110
|
+
Write(p lint.Problem)
|
111
|
+
}
|
112
|
+
|
113
|
+
type jsonFormatter struct{}
|
114
|
+
|
115
|
+
type jsonProblem struct {
|
116
|
+
Filename string `json:"filename"`
|
117
|
+
Line int `json:"line"`
|
118
|
+
Column int `json:"column"`
|
119
|
+
Text string `json:"text"`
|
120
|
+
Link string `json:"link"`
|
121
|
+
Confidence float64 `json:"confidence"`
|
122
|
+
LineText string `json:"linetext"`
|
123
|
+
Category string `json:"category"`
|
124
|
+
}
|
125
|
+
|
126
|
+
func (jf *jsonFormatter) Write(p lint.Problem) {
|
127
|
+
b, err := json.Marshal(jsonProblem{
|
128
|
+
Filename: p.Position.Filename,
|
129
|
+
Line: p.Position.Line,
|
130
|
+
Column: p.Position.Column,
|
131
|
+
Text: p.Text,
|
132
|
+
Link: p.Link,
|
133
|
+
Confidence: p.Confidence,
|
134
|
+
LineText: p.LineText,
|
135
|
+
Category: p.Category,
|
136
|
+
})
|
137
|
+
|
138
|
+
if err != nil {
|
139
|
+
fmt.Fprintf(os.Stderr, "an unknown error as occured: %s", err.Error())
|
140
|
+
os.Exit(1)
|
141
|
+
}
|
142
|
+
|
143
|
+
os.Stdout.Write(b)
|
144
|
+
}
|
145
|
+
|
146
|
+
func isDir(filename string) bool {
|
147
|
+
fi, err := os.Stat(filename)
|
148
|
+
return err == nil && fi.IsDir()
|
149
|
+
}
|
150
|
+
|
151
|
+
func exists(filename string) bool {
|
152
|
+
_, err := os.Stat(filename)
|
153
|
+
return err == nil
|
154
|
+
}
|
155
|
+
|
156
|
+
func lintFiles(filenames ...string) {
|
157
|
+
files := make(map[string][]byte)
|
158
|
+
for _, filename := range filenames {
|
159
|
+
src, err := ioutil.ReadFile(filename)
|
160
|
+
if err != nil {
|
161
|
+
fmt.Fprintln(os.Stderr, err)
|
162
|
+
continue
|
163
|
+
}
|
164
|
+
files[filename] = src
|
165
|
+
}
|
166
|
+
|
167
|
+
l := new(lint.Linter)
|
168
|
+
ps, err := l.LintFiles(files)
|
169
|
+
if err != nil {
|
170
|
+
fmt.Fprintf(os.Stderr, "%v\n", err)
|
171
|
+
return
|
172
|
+
}
|
173
|
+
for _, p := range ps {
|
174
|
+
if p.Confidence >= *minConfidence {
|
175
|
+
formatter.Write(p)
|
176
|
+
suggestions++
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
func lintDir(dirname string) {
|
182
|
+
pkg, err := build.ImportDir(dirname, 0)
|
183
|
+
lintImportedPackage(pkg, err)
|
184
|
+
}
|
185
|
+
|
186
|
+
func lintPackage(pkgname string) {
|
187
|
+
pkg, err := build.Import(pkgname, ".", 0)
|
188
|
+
lintImportedPackage(pkg, err)
|
189
|
+
}
|
190
|
+
|
191
|
+
func lintImportedPackage(pkg *build.Package, err error) {
|
192
|
+
if err != nil {
|
193
|
+
if _, nogo := err.(*build.NoGoError); nogo {
|
194
|
+
// Don't complain if the failure is due to no Go source files.
|
195
|
+
return
|
196
|
+
}
|
197
|
+
fmt.Fprintln(os.Stderr, err)
|
198
|
+
return
|
199
|
+
}
|
200
|
+
|
201
|
+
var files []string
|
202
|
+
files = append(files, pkg.GoFiles...)
|
203
|
+
files = append(files, pkg.CgoFiles...)
|
204
|
+
files = append(files, pkg.TestGoFiles...)
|
205
|
+
if pkg.Dir != "." {
|
206
|
+
for i, f := range files {
|
207
|
+
files[i] = filepath.Join(pkg.Dir, f)
|
208
|
+
}
|
209
|
+
}
|
210
|
+
// TODO(dsymonds): Do foo_test too (pkg.XTestGoFiles)
|
211
|
+
|
212
|
+
lintFiles(files...)
|
213
|
+
}
|