|
| 1 | +package processors |
| 2 | + |
| 3 | +import "github.com/golangci/golangci-lint/pkg/config" |
| 4 | + |
| 5 | +var defaultLintersExclusions = map[string][]config.ExcludeRule{ |
| 6 | + "comments": { |
| 7 | + { |
| 8 | + // Annoying issue about not having a comment. The rare codebase has such comments. |
| 9 | + // CheckPackageComment, CheckExportedFunctionDocs, CheckExportedTypeDocs, CheckExportedVarDocs |
| 10 | + BaseRule: config.BaseRule{ |
| 11 | + Text: "(ST1000|ST1020|ST1021|ST1022)", |
| 12 | + Linters: []string{"stylecheck"}, |
| 13 | + InternalReference: "EXC0011", |
| 14 | + }, |
| 15 | + }, |
| 16 | + { |
| 17 | + // Annoying issue about not having a comment. The rare codebase has such comments. |
| 18 | + // rule: exported |
| 19 | + BaseRule: config.BaseRule{ |
| 20 | + Text: `exported (.+) should have comment( \(or a comment on this block\))? or be unexported`, |
| 21 | + Linters: []string{"revive"}, |
| 22 | + InternalReference: "EXC0012", |
| 23 | + }, |
| 24 | + }, |
| 25 | + { |
| 26 | + // Annoying issue about not having a comment. The rare codebase has such comments. |
| 27 | + // rule: package-comments |
| 28 | + BaseRule: config.BaseRule{ |
| 29 | + Text: `package comment should be of the form "(.+)..."`, |
| 30 | + Linters: []string{"revive"}, |
| 31 | + InternalReference: "EXC0013", |
| 32 | + }, |
| 33 | + }, |
| 34 | + { |
| 35 | + // Annoying issue about not having a comment. The rare codebase has such comments. |
| 36 | + // rule: exported |
| 37 | + BaseRule: config.BaseRule{ |
| 38 | + Text: `comment on exported (.+) should be of the form "(.+)..."`, |
| 39 | + Linters: []string{"revive"}, |
| 40 | + InternalReference: "EXC0014", |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + // Annoying issue about not having a comment. The rare codebase has such comments. |
| 45 | + // rule: package-comments |
| 46 | + BaseRule: config.BaseRule{ |
| 47 | + Text: `should have a package comment`, |
| 48 | + Linters: []string{"revive"}, |
| 49 | + InternalReference: "EXC0015", |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + "stdErrorHandling": { |
| 54 | + { |
| 55 | + // Almost all programs ignore errors on these functions and in most cases it's ok. |
| 56 | + BaseRule: config.BaseRule{ |
| 57 | + Text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close" + |
| 58 | + "|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked", |
| 59 | + Linters: []string{"errcheck"}, |
| 60 | + InternalReference: "EXC0001", |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + "commonFalsePositives": { |
| 65 | + { |
| 66 | + // Too many false-positives on 'unsafe' usage. |
| 67 | + BaseRule: config.BaseRule{ |
| 68 | + Text: "G103: Use of unsafe calls should be audited", |
| 69 | + Linters: []string{"gosec"}, |
| 70 | + InternalReference: "EXC0006", |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + // Too many false-positives for parametrized shell calls. |
| 75 | + BaseRule: config.BaseRule{ |
| 76 | + Text: "G204: Subprocess launched with variable", |
| 77 | + Linters: []string{"gosec"}, |
| 78 | + InternalReference: "EXC0007", |
| 79 | + }, |
| 80 | + }, |
| 81 | + { |
| 82 | + // False positive is triggered by 'src, err := ioutil.ReadFile(filename)'. |
| 83 | + BaseRule: config.BaseRule{ |
| 84 | + Text: "G304: Potential file inclusion via variable", |
| 85 | + Linters: []string{"gosec"}, |
| 86 | + InternalReference: "EXC0010", |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + "legacy": { |
| 91 | + { |
| 92 | + // Common false positives. |
| 93 | + BaseRule: config.BaseRule{ |
| 94 | + Text: "(possible misuse of unsafe.Pointer|should have signature)", |
| 95 | + Linters: []string{"govet"}, |
| 96 | + InternalReference: "EXC0004", |
| 97 | + }, |
| 98 | + }, |
| 99 | + { |
| 100 | + // Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore. |
| 101 | + // CheckScopedBreak |
| 102 | + BaseRule: config.BaseRule{ |
| 103 | + Text: "SA4011", |
| 104 | + Linters: []string{"staticcheck"}, |
| 105 | + InternalReference: "EXC0005", |
| 106 | + }, |
| 107 | + }, |
| 108 | + { |
| 109 | + // Duplicated errcheck checks. |
| 110 | + // Errors unhandled. |
| 111 | + BaseRule: config.BaseRule{ |
| 112 | + Text: "G104", |
| 113 | + Linters: []string{"gosec"}, |
| 114 | + InternalReference: "EXC0008", |
| 115 | + }, |
| 116 | + }, |
| 117 | + { |
| 118 | + // Too many issues in popular repos. |
| 119 | + BaseRule: config.BaseRule{ |
| 120 | + Text: "(G301|G302|G307): Expect (directory permissions to be 0750|file permissions to be 0600) or less", |
| 121 | + Linters: []string{"gosec"}, |
| 122 | + InternalReference: "EXC0009", |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | +} |
| 127 | + |
| 128 | +func getDefaultLintersExclusions(names []string) []config.ExcludeRule { |
| 129 | + var rules []config.ExcludeRule |
| 130 | + |
| 131 | + for _, name := range names { |
| 132 | + rules = append(rules, defaultLintersExclusions[name]...) |
| 133 | + } |
| 134 | + |
| 135 | + return rules |
| 136 | +} |
0 commit comments