Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

Commit ce60723

Browse files
author
Dinesh Kumar
committed
2 parents 22e3b9e + fb4f8c1 commit ce60723

File tree

7 files changed

+55
-31
lines changed

7 files changed

+55
-31
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Golint is a linter for Go source code.
66

77
Golint requires Go 1.6 or later.
88

9-
go get -u github.com/golang/lint/golint
9+
go get -u golang.org/x/lint/golint
1010

1111
## Usage
1212

@@ -41,15 +41,18 @@ Golint makes suggestions for many of the mechanically checkable items listed in
4141
[Effective Go](https://golang.org/doc/effective_go.html) and the
4242
[CodeReviewComments wiki page](https://golang.org/wiki/CodeReviewComments).
4343

44-
If you find an established style that is frequently violated, and which
45-
you think golint could statically check,
46-
[file an issue](https://github.com/golang/lint/issues).
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.
4750

4851
## Contributions
4952

50-
Contributions to this project are welcome, though please send mail before
51-
starting work on anything major. Contributors retain their copyright, so we
52-
need you to fill out
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
5356
[a short form](https://developers.google.com/open-source/cla/individual)
5457
before we can accept your contribution.
5558

golint/golint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"path/filepath"
1717
"strings"
1818

19-
"github.com/golang/lint"
19+
"golang.org/x/lint"
2020
)
2121

2222
var (

golint/import.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ import (
2222
"strings"
2323
)
2424

25-
var buildContext = build.Default
26-
2725
const vendorDir = "vendor"
2826

2927
var (
30-
goroot = filepath.Clean(runtime.GOROOT())
31-
gorootSrc = filepath.Join(goroot, "src")
28+
buildContext = build.Default
29+
goroot = filepath.Clean(runtime.GOROOT())
30+
gorootSrc = filepath.Join(goroot, "src")
3231
)
3332

3433
// importPathsNoDotExpansion returns the import paths to use for the given

lint.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ func (f *file) lintExported() {
527527
})
528528
}
529529

530-
var allCapsRE = regexp.MustCompile(`^[A-Z0-9_]+$`)
530+
var (
531+
allCapsRE = regexp.MustCompile(`^[A-Z0-9_]+$`)
532+
anyCapsRE = regexp.MustCompile(`[A-Z]`)
533+
)
531534

532535
// knownNameExceptions is a set of names that are known to be exempt from naming checks.
533536
// This is usually because they are constrained by having to match names in the
@@ -544,6 +547,9 @@ func (f *file) lintNames() {
544547
if strings.Contains(f.f.Name.Name, "_") && !strings.HasSuffix(f.f.Name.Name, "_test") {
545548
f.errorf(f.f, 1, link("http://golang.org/doc/effective_go.html#package-names"), category("naming"), "don't use an underscore in package name")
546549
}
550+
if anyCapsRE.MatchString(f.f.Name.Name) {
551+
f.errorf(f.f, 1, link("http://golang.org/doc/effective_go.html#package-names"), category("mixed-caps"), "don't use MixedCaps in package name; %s should be %s", f.f.Name.Name, strings.ToLower(f.f.Name.Name))
552+
}
547553

548554
check := func(id *ast.Ident, thing string) {
549555
if id.Name == "_" {
@@ -1078,20 +1084,25 @@ func (f *file) lintRanges() {
10781084
if !ok {
10791085
return true
10801086
}
1081-
if rs.Value == nil {
1082-
// for x = range m { ... }
1083-
return true // single var form
1084-
}
1085-
if !isIdent(rs.Value, "_") {
1086-
// for ?, y = range m { ... }
1087+
1088+
if isIdent(rs.Key, "_") && (rs.Value == nil || isIdent(rs.Value, "_")) {
1089+
p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for range ...`")
1090+
1091+
newRS := *rs // shallow copy
1092+
newRS.Value = nil
1093+
newRS.Key = nil
1094+
p.ReplacementLine = f.firstLineOf(&newRS, rs)
1095+
10871096
return true
10881097
}
10891098

1090-
p := f.errorf(rs.Value, 1, category("range-loop"), "should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", f.render(rs.Key), rs.Tok)
1099+
if isIdent(rs.Value, "_") {
1100+
p := f.errorf(rs.Value, 1, category("range-loop"), "should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", f.render(rs.Key), rs.Tok)
10911101

1092-
newRS := *rs // shallow copy
1093-
newRS.Value = nil
1094-
p.ReplacementLine = f.firstLineOf(&newRS, rs)
1102+
newRS := *rs // shallow copy
1103+
newRS.Value = nil
1104+
p.ReplacementLine = f.firstLineOf(&newRS, rs)
1105+
}
10951106

10961107
return true
10971108
})

misc/emacs/golint.el

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
;;; golint.el --- lint for the Go source code
22

33
;; Copyright 2013 The Go Authors. All rights reserved.
4-
;; Use of this source code is governed by a BSD-style
5-
;; license that can be found in the LICENSE file.
64

5+
;; License: BSD-3-clause
76
;; URL: https://github.com/golang/lint
87

98
;;; Commentary:
@@ -17,15 +16,16 @@
1716
;; Usage:
1817
;; C-x `
1918
;; Jump directly to the line in your code which caused the first message.
20-
;;
19+
;;
2120
;; For more usage, see Compilation-Mode:
2221
;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html
2322

2423
;;; Code:
24+
2525
(require 'compile)
2626

27-
(defun go-lint-buffer-name (mode)
28-
"*Golint*")
27+
(defun go-lint-buffer-name (mode)
28+
"*Golint*")
2929

3030
(defun golint-process-setup ()
3131
"Setup compilation variables and buffer for `golint'."
@@ -36,12 +36,13 @@
3636
(set (make-local-variable 'compilation-scroll-output) nil)
3737
(set (make-local-variable 'compilation-disable-input) t)
3838
(set (make-local-variable 'compilation-process-setup-function)
39-
'golint-process-setup)
40-
)
39+
'golint-process-setup))
4140

4241
;;;###autoload
4342
(defun golint ()
44-
"Run golint on the current file and populate the fix list. Pressing C-x ` will jump directly to the line in your code which caused the first message."
43+
"Run golint on the current file and populate the fix list.
44+
Pressing \"C-x `\" jumps directly to the line in your code which
45+
caused the first message."
4546
(interactive)
4647
(compilation-start
4748
(mapconcat #'shell-quote-argument

testdata/pkg-caps.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// MixedCaps package name
2+
3+
// Package PkgName ...
4+
package PkgName // MATCH /don't use MixedCaps in package name/

testdata/range.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ func f() {
1616
for y, _ = range m { // MATCH /should omit 2nd value.*range.*equivalent.*for y = range/
1717
}
1818

19+
for _ = range m { // MATCH /should omit values.*range.*equivalent.*for range/
20+
}
21+
22+
for _, _ = range m { // MATCH /should omit values.*range.*equivalent.*for range/
23+
}
24+
1925
// all OK:
2026
for x := range m {
2127
_ = x

0 commit comments

Comments
 (0)