|
1 |
| ---- |
2 |
| -# golangci-lint configuration file made by @ccoVeille |
3 |
| -# Source: https://github.com/ccoVeille/golangci-lint-config-examples/tree/main/03-safe |
4 |
| -# License: MIT |
5 |
| -# |
6 |
| -linters: |
7 |
| - # some linters are enabled by default |
8 |
| - # https://golangci-lint.run/usage/linters/ |
9 |
| - # |
10 |
| - # enable some extra linters |
11 |
| - enable: |
12 |
| - # Errcheck is a program for checking for unchecked errors in Go code. |
13 |
| - - errcheck |
14 |
| - |
15 |
| - # Linter for Go source code that specializes in simplifying code. |
16 |
| - - gosimple |
17 |
| - |
18 |
| - # Vet examines Go source code and reports suspicious constructs. |
19 |
| - - govet |
20 |
| - |
21 |
| - # Detects when assignments to existing variables are not used. |
22 |
| - - ineffassign |
23 |
| - |
24 |
| - # It's a set of rules from staticcheck. See https://staticcheck.io/ |
25 |
| - - staticcheck |
26 |
| - |
27 |
| - # Fast, configurable, extensible, flexible, and beautiful linter for Go. |
28 |
| - # Drop-in replacement of golint. |
29 |
| - - revive |
30 |
| - |
31 |
| - # check imports order and makes it always deterministic. |
32 |
| - - gci |
33 |
| - |
34 |
| - # make sure to use t.Helper() when needed |
35 |
| - - thelper |
36 |
| - |
37 |
| - # mirror suggests rewrites to avoid unnecessary []byte/string conversion |
38 |
| - - mirror |
39 |
| - |
40 |
| - # detect the possibility to use variables/constants from the Go standard library. |
41 |
| - - usestdlibvars |
42 |
| - |
43 |
| - # Finds commonly misspelled English words. |
44 |
| - - misspell |
45 |
| - |
46 |
| - # Checks for duplicate words in the source code. |
47 |
| - - dupword |
48 |
| - |
49 |
| -linters-settings: |
50 |
| - gci: # define the section orders for imports |
51 |
| - sections: |
52 |
| - # Standard section: captures all standard packages. |
53 |
| - - standard |
54 |
| - # Default section: catchall that is not standard or custom |
55 |
| - - default |
56 |
| - # linters that related to local tool, so they should be separated |
57 |
| - - localmodule |
58 |
| - |
59 |
| - revive: |
60 |
| - rules: |
61 |
| - # these are the default revive rules |
62 |
| - # you can remove the whole "rules" node if you want |
63 |
| - # BUT |
64 |
| - # ! /!\ they all need to be present when you want to add more rules than the default ones |
65 |
| - # otherwise, you won't have the default rules, but only the ones you define in the "rules" node |
66 |
| - |
67 |
| - # Blank import should be only in a main or test package, or have a comment justifying it. |
68 |
| - - name: blank-imports |
69 |
| - |
70 |
| - # context.Context() should be the first parameter of a function when provided as argument. |
71 |
| - - name: context-as-argument |
72 |
| - |
73 |
| - # Basic types should not be used as a key in `context.WithValue` |
74 |
| - - name: context-keys-type |
75 |
| - |
76 |
| - # Importing with `.` makes the programs much harder to understand |
77 |
| - - name: dot-imports |
| 1 | +# This is a golangci-lint config file for Clipper CI workflows |
| 2 | +# For more details on configuring golangci-lint, visit: https://golangci-lint.run/usage/configuration/ |
| 3 | +# Special thanks to @ccoVeille for the original configuration |
78 | 4 |
|
79 |
| - # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. |
80 |
| - - name: empty-block |
| 5 | +run: |
| 6 | + # Timeout for golangci-lint execution |
| 7 | + timeout: 5m |
81 | 8 |
|
82 |
| - # for better readability, variables of type `error` must be named with the prefix `err`. |
83 |
| - - name: error-naming |
| 9 | + # Additional parameters to ensure all files are checked and caching is used |
| 10 | + modules-download-mode: readonly |
| 11 | + allow-parallel-runners: true |
84 | 12 |
|
85 |
| - # for better readability, the errors should be last in the list of returned values by a function. |
86 |
| - - name: error-return |
87 |
| - |
88 |
| - # for better readability, error messages should not be capitalized or end with punctuation or a newline. |
89 |
| - - name: error-strings |
90 |
| - |
91 |
| - # report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible |
92 |
| - - name: errorf |
93 |
| - |
94 |
| - # incrementing an integer variable by 1 is recommended to be done using the `++` operator |
95 |
| - - name: increment-decrement |
96 |
| - |
97 |
| - # highlights redundant else-blocks that can be eliminated from the code |
98 |
| - - name: indent-error-flow |
99 |
| - |
100 |
| - # This rule suggests a shorter way of writing ranges that do not use the second value. |
101 |
| - - name: range |
102 |
| - |
103 |
| - # receiver names in a method should reflect the struct name (p for Person, for example) |
104 |
| - - name: receiver-naming |
105 |
| - |
106 |
| - # redefining built in names (true, false, append, make) can lead to bugs very difficult to detect. |
107 |
| - - name: redefines-builtin-id |
108 |
| - |
109 |
| - # redundant else-blocks that can be eliminated from the code. |
110 |
| - - name: superfluous-else |
111 |
| - |
112 |
| - # prevent confusing name for variables when using `time` package |
113 |
| - - name: time-naming |
114 |
| - |
115 |
| - # warns when an exported function or method returns a value of an un-exported type. |
116 |
| - - name: unexported-return |
117 |
| - |
118 |
| - # spots and proposes to remove unreachable code. also helps to spot errors |
119 |
| - - name: unreachable-code |
120 |
| - |
121 |
| - # Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug. |
122 |
| - - name: unused-parameter |
123 |
| - |
124 |
| - # report when a variable declaration can be simplified |
125 |
| - - name: var-declaration |
126 |
| - |
127 |
| - # warns when initialism, variable or package naming conventions are not followed. |
128 |
| - - name: var-naming |
129 |
| - |
130 |
| - dupword: |
131 |
| - # Keywords used to ignore detection. |
132 |
| - # Default: [] |
133 |
| - ignore: |
134 |
| - # - "blah" # this will accept "blah blah …" as a valid duplicate word |
135 |
| - |
136 |
| - misspell: |
137 |
| - # Correct spellings using locale preferences for US or UK. |
138 |
| - # Setting locale to US will correct the British spelling of 'colour' to 'color'. |
139 |
| - # Default ("") is to use a neutral variety of English. |
140 |
| - locale: US |
141 |
| - |
142 |
| - # List of words to ignore |
143 |
| - # among the one defined in https://github.com/golangci/misspell/blob/master/words.go |
144 |
| - ignore-words: |
145 |
| - # - valor |
146 |
| - # - and |
| 13 | +linters: |
| 14 | + # Disable all linters initially |
| 15 | + disable-all: true |
147 | 16 |
|
148 |
| - # Extra word corrections. |
149 |
| - extra-words: |
150 |
| - # - typo: "whattever" |
151 |
| - # correction: "whatever" |
| 17 | + # Enable specific linters with comments explaining each one |
| 18 | + enable: |
| 19 | + - errcheck # Checks for unchecked errors in Go code |
| 20 | + - thelper # Detects Go test helpers without t.Helper() call |
| 21 | + - unused # Checks for unused constants, variables, functions, and types |
| 22 | + - unparam # Reports unused function parameters |
| 23 | + - unconvert # Removes unnecessary type conversions |
| 24 | + - whitespace # Detects leading and trailing whitespace |
| 25 | + - ineffassign # Detects when assignments to existing variables are not used |
| 26 | + - asasalint # Checks for passing []any as any in variadic func(...any) |
| 27 | + - wastedassign # Finds wasted assignment statements |
| 28 | + - misspell # Finds commonly misspelled English words in comments |
| 29 | + - funlen # Detects long functions |
| 30 | + - bodyclose # Checks whether HTTP response body is closed successfully |
| 31 | + - reassign # Checks that package variables are not reassigned |
| 32 | + - tagliatelle # Checks struct tags |
| 33 | + - decorder # Checks declaration order and count of types, constants, variables, and functions |
| 34 | + - revive # Fast, configurable, extensible linter for Go. Drop-in replacement for golint |
| 35 | + - dupword # Checks for duplicate words in the source code |
| 36 | + - cyclop # Checks function and package cyclomatic complexity |
| 37 | + - gocognit # Computes and checks the cognitive complexity of functions |
| 38 | + - goconst # Finds repeated strings that could be replaced by a constant |
| 39 | + - gocritic # Provides diagnostics that check for bugs, performance, and style issues |
| 40 | + - godot # Checks if comments end in a period |
| 41 | + - godox # Detects FIXME, TODO, and other comment keywords |
| 42 | + - errname # Checks that sentinel errors are prefixed with `Err` and error types are suffixed with `Error` |
| 43 | + - varnamelen # Checks that the length of a variable's name matches its scope |
| 44 | + - testpackage # Ensures use of a separate _test package |
| 45 | + - gochecknoinits # Checks that no init functions are present in Go code |
| 46 | + |
| 47 | +issues: |
| 48 | + # Use default exclusions |
| 49 | + exclude-use-default: true |
| 50 | + |
| 51 | + # Set limits for reported issues |
| 52 | + max-issues-per-linter: 0 |
| 53 | + max-same-issues: 0 |
| 54 | + |
| 55 | +severity: |
| 56 | + # Severity levels for issues |
| 57 | + error: true |
| 58 | + warning: true |
| 59 | + info: true |
| 60 | + ignore: false |
| 61 | + |
| 62 | +# Performance optimization settings |
| 63 | +performance: |
| 64 | + golangci-lint: |
| 65 | + concurrency: 4 |
| 66 | + max-same-issues: 3 |
| 67 | + max-issues-per-linter: 10 |
| 68 | + |
| 69 | +# Caching settings to improve performance |
| 70 | +caches: |
| 71 | + enable: true |
| 72 | + cache-dir: /tmp/golangci-lint-cache |
| 73 | + |
| 74 | +# CI-specific settings |
| 75 | +ci: |
| 76 | + # Enable fail-fast to stop on the first failure |
| 77 | + fail-fast: true |
| 78 | + |
| 79 | + # Run golangci-lint as a pre-commit hook |
| 80 | + pre-commit: |
| 81 | + run: true |
| 82 | + mode: diff |
0 commit comments