Skip to content

Commit b824c10

Browse files
ldezpull[bot]
authored andcommitted
dev: clean DefaultExcludePatterns and improve CLI render (#4638)
1 parent ad545e6 commit b824c10

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

pkg/commands/flagsets.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
120120

121121
func getDefaultIssueExcludeHelp() string {
122122
parts := []string{color.GreenString("Use or not use default excludes:")}
123+
123124
for _, ep := range config.DefaultExcludePatterns {
124125
parts = append(parts,
125-
fmt.Sprintf(" # %s %s: %s", ep.ID, ep.Linter, ep.Why),
126-
fmt.Sprintf(" - %s", color.YellowString(ep.Pattern)),
127-
"",
126+
fmt.Sprintf(" - %s (%s): %s", color.BlueString(ep.ID), color.CyanString(ep.Linter), ep.Why),
127+
fmt.Sprintf(` Pattern: %s`, color.YellowString(`'`+ep.Pattern+`'`)),
128128
)
129129
}
130+
130131
return strings.Join(parts, "\n")
131132
}
132133

pkg/config/issues.go

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,93 +14,92 @@ var DefaultExcludePatterns = []ExcludePattern{
1414
Pattern: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close" +
1515
"|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked",
1616
Linter: "errcheck",
17-
Why: "Almost all programs ignore errors on these functions and in most cases it's ok",
17+
Why: "Almost all programs ignore errors on these functions and in most cases it's ok.",
1818
},
1919
{
20-
ID: "EXC0002",
20+
ID: "EXC0002", // TODO(ldez): should be remove in v2
2121
Pattern: "(comment on exported (method|function|type|const)|" +
2222
"should have( a package)? comment|comment should be of the form)",
2323
Linter: "golint",
24-
Why: "Annoying issue about not having a comment. The rare codebase has such comments",
24+
Why: "Annoying issue about not having a comment. The rare codebase has such comments.",
2525
},
2626
{
27-
ID: "EXC0003",
27+
ID: "EXC0003", // TODO(ldez): should be remove in v2
2828
Pattern: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this",
2929
Linter: "golint",
30-
Why: "False positive when tests are defined in package 'test'",
30+
Why: "False positive when tests are defined in package 'test'.",
3131
},
3232
{
3333
ID: "EXC0004",
3434
Pattern: "(possible misuse of unsafe.Pointer|should have signature)",
3535
Linter: "govet",
36-
Why: "Common false positives",
36+
Why: "Common false positives.",
3737
},
3838
{
3939
ID: "EXC0005",
40-
Pattern: "ineffective break statement. Did you mean to break out of the outer loop",
40+
Pattern: "SA4011", // CheckScopedBreak
4141
Linter: "staticcheck",
42-
Why: "Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore",
42+
Why: "Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore.",
4343
},
4444
{
4545
ID: "EXC0006",
46-
Pattern: "Use of unsafe calls should be audited",
46+
Pattern: "G103: Use of unsafe calls should be audited",
4747
Linter: "gosec",
48-
Why: "Too many false-positives on 'unsafe' usage",
48+
Why: "Too many false-positives on 'unsafe' usage.",
4949
},
5050
{
5151
ID: "EXC0007",
52-
Pattern: "Subprocess launch(ed with variable|ing should be audited)",
52+
Pattern: "G204: Subprocess launched with variable",
5353
Linter: "gosec",
54-
Why: "Too many false-positives for parametrized shell calls",
54+
Why: "Too many false-positives for parametrized shell calls.",
5555
},
5656
{
5757
ID: "EXC0008",
58-
Pattern: "(G104)",
58+
Pattern: "G104", // Errors unhandled.
5959
Linter: "gosec",
60-
Why: "Duplicated errcheck checks",
60+
Why: "Duplicated errcheck checks.",
6161
},
6262
{
6363
ID: "EXC0009",
64-
Pattern: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)",
64+
Pattern: "(G301|G302|G307): Expect (directory permissions to be 0750|file permissions to be 0600) or less",
6565
Linter: "gosec",
66-
Why: "Too many issues in popular repos",
66+
Why: "Too many issues in popular repos.",
6767
},
6868
{
6969
ID: "EXC0010",
70-
Pattern: "Potential file inclusion via variable",
70+
Pattern: "G304: Potential file inclusion via variable",
7171
Linter: "gosec",
72-
Why: "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'",
72+
Why: "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'.",
7373
},
7474
{
75-
ID: "EXC0011",
76-
Pattern: "(comment on exported (method|function|type|const)|" +
77-
"should have( a package)? comment|comment should be of the form)",
78-
Linter: "stylecheck",
79-
Why: "Annoying issue about not having a comment. The rare codebase has such comments",
75+
ID: "EXC0011",
76+
Pattern: "(ST1000|ST1020|ST1021|ST1022)", // CheckPackageComment, CheckExportedFunctionDocs, CheckExportedTypeDocs, CheckExportedVarDocs
77+
Linter: "stylecheck",
78+
Why: "Annoying issue about not having a comment. The rare codebase has such comments.",
8079
},
8180
{
8281
ID: "EXC0012",
83-
Pattern: `exported (.+) should have comment( \(or a comment on this block\))? or be unexported`,
82+
Pattern: `exported (.+) should have comment( \(or a comment on this block\))? or be unexported`, // rule: exported
8483
Linter: "revive",
85-
Why: "Annoying issue about not having a comment. The rare codebase has such comments",
84+
Why: "Annoying issue about not having a comment. The rare codebase has such comments.",
8685
},
8786
{
8887
ID: "EXC0013",
89-
Pattern: `package comment should be of the form "(.+)...`,
88+
Pattern: `package comment should be of the form "(.+)..."`, // rule: package-comments
9089
Linter: "revive",
91-
Why: "Annoying issue about not having a comment. The rare codebase has such comments",
90+
Why: "Annoying issue about not having a comment. The rare codebase has such comments.",
9291
},
9392
{
9493
ID: "EXC0014",
95-
Pattern: `comment on exported (.+) should be of the form "(.+)..."`,
94+
Pattern: `comment on exported (.+) should be of the form "(.+)..."`, // rule: exported
9695
Linter: "revive",
97-
Why: "Annoying issue about not having a comment. The rare codebase has such comments",
96+
Why: "Annoying issue about not having a comment. The rare codebase has such comments.",
9897
},
9998
{
10099
ID: "EXC0015",
101-
Pattern: `should have a package comment`,
100+
Pattern: `should have a package comment`, // rule: package-comments
102101
Linter: "revive",
103-
Why: "Annoying issue about not having a comment. The rare codebase has such comments",
102+
Why: "Annoying issue about not having a comment. The rare codebase has such comments.",
104103
},
105104
}
106105

0 commit comments

Comments
 (0)