LSP-server-example

Форк
0
/
.golangci.yaml 
346 строк · 16.1 Кб
1
# This code is licensed under the terms of the MIT license https://opensource.org/license/mit
2
# Copyright (c) 2021 Marat Reymers
3

4
## Golden config for golangci-lint v1.56.2
5
#
6
# This is the best config for golangci-lint based on my experience and opinion.
7
# It is very strict, but not extremely strict.
8
# Feel free to adapt and change it for your needs.
9

10
run:
11
  # Timeout for analysis, e.g. 30s, 5m.
12
  # Default: 1m
13
  timeout: 3m
14
  skip-files:
15
    - internal/protocol/uri.go
16
    - internal/utils/pathutil/util.go
17

18

19
# This file contains only configs which differ from defaults.
20
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
21
linters-settings:
22
  cyclop:
23
    # The maximal code complexity to report.
24
    # Default: 10
25
    max-complexity: 30
26
    # The maximal average package complexity.
27
    # If it's higher than 0.0 (float) the check is enabled
28
    # Default: 0.0
29
    package-average: 10.0
30

31
  errcheck:
32
    # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
33
    # Such cases aren't reported by default.
34
    # Default: false
35
    check-type-assertions: true
36

37
  exhaustive:
38
    # Program elements to check for exhaustiveness.
39
    # Default: [ switch ]
40
    check:
41
      - switch
42
      - map
43

44
  exhaustruct:
45
    # List of regular expressions to exclude struct packages and their names from checks.
46
    # Regular expressions must match complete canonical struct package/name/structname.
47
    # Default: []
48
    exclude:
49
      # std libs
50
      - "^net/http.Client$"
51
      - "^net/http.Cookie$"
52
      - "^net/http.Request$"
53
      - "^net/http.Response$"
54
      - "^net/http.Server$"
55
      - "^net/http.Transport$"
56
      - "^net/url.URL$"
57
      - "^os/exec.Cmd$"
58
      - "^reflect.StructField$"
59
      # public libs
60
      - "^github.com/Shopify/sarama.Config$"
61
      - "^github.com/Shopify/sarama.ProducerMessage$"
62
      - "^github.com/mitchellh/mapstructure.DecoderConfig$"
63
      - "^github.com/prometheus/client_golang/.+Opts$"
64
      - "^github.com/spf13/cobra.Command$"
65
      - "^github.com/spf13/cobra.CompletionOptions$"
66
      - "^github.com/stretchr/testify/mock.Mock$"
67
      - "^github.com/testcontainers/testcontainers-go.+Request$"
68
      - "^github.com/testcontainers/testcontainers-go.FromDockerfile$"
69
      - "^golang.org/x/tools/go/analysis.Analyzer$"
70
      - "^google.golang.org/protobuf/.+Options$"
71
      - "^gopkg.in/yaml.v3.Node$"
72

73
  funlen:
74
    # Checks the number of lines in a function.
75
    # If lower than 0, disable the check.
76
    # Default: 60
77
    lines: 100
78
    # Checks the number of statements in a function.
79
    # If lower than 0, disable the check.
80
    # Default: 40
81
    statements: 50
82
    # Ignore comments when counting lines.
83
    # Default false
84
    ignore-comments: true
85

86
  gocognit:
87
    # Minimal code complexity to report.
88
    # Default: 30 (but we recommend 10-20)
89
    min-complexity: 20
90

91
  gocritic:
92
    # Settings passed to gocritic.
93
    # The settings key is the name of a supported gocritic checker.
94
    # The list of supported checkers can be find in https://go-critic.github.io/overview.
95
    settings:
96
      captLocal:
97
        # Whether to restrict checker to params only.
98
        # Default: true
99
        paramsOnly: false
100
      underef:
101
        # Whether to skip (*x).method() calls where x is a pointer receiver.
102
        # Default: true
103
        skipRecvDeref: false
104

105
  gomnd:
106
    # List of function patterns to exclude from analysis.
107
    # Values always ignored: `time.Date`,
108
    # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
109
    # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
110
    # Default: []
111
    ignored-functions:
112
      - flag.Arg
113
      - flag.Duration.*
114
      - flag.Float.*
115
      - flag.Int.*
116
      - flag.Uint.*
117
      - os.Chmod
118
      - os.Mkdir.*
119
      - os.OpenFile
120
      - os.WriteFile
121
      - prometheus.ExponentialBuckets.*
122
      - prometheus.LinearBuckets
123

124
  gomodguard:
125
    blocked:
126
      # List of blocked modules.
127
      # Default: []
128
      modules:
129
        - github.com/golang/protobuf:
130
            recommendations:
131
              - google.golang.org/protobuf
132
            reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules"
133
        - github.com/satori/go.uuid:
134
            recommendations:
135
              - github.com/google/uuid
136
            reason: "satori's package is not maintained"
137
        - github.com/gofrs/uuid:
138
            recommendations:
139
              - github.com/gofrs/uuid/v5
140
            reason: "gofrs' package was not go module before v5"
141

142
  govet:
143
    # Enable all analyzers.
144
    # Default: false
145
    enable-all: true
146
    # Disable analyzers by name.
147
    # Run `go tool vet help` to see all analyzers.
148
    # Default: []
149
    disable:
150
      - fieldalignment # too strict
151
    # Settings per analyzer.
152
    settings:
153
      shadow:
154
        # Whether to be strict about shadowing; can be noisy.
155
        # Default: false
156
        strict: true
157

158
  inamedparam:
159
    # Skips check for interface methods with only a single parameter.
160
    # Default: false
161
    skip-single-param: true
162

163
  nakedret:
164
    # Make an issue if func has more lines of code than this setting, and it has naked returns.
165
    # Default: 30
166
    max-func-lines: 0
167

168
  nolintlint:
169
    # Exclude following linters from requiring an explanation.
170
    # Default: []
171
    allow-no-explanation: [ funlen, gocognit, lll ]
172
    # Enable to require an explanation of nonzero length after each nolint directive.
173
    # Default: false
174
    require-explanation: true
175
    # Enable to require nolint directives to mention the specific linter being suppressed.
176
    # Default: false
177
    require-specific: true
178

179
  perfsprint:
180
    # Optimizes into strings concatenation.
181
    # Default: true
182
    strconcat: false
183

184
  rowserrcheck:
185
    # database/sql is always checked
186
    # Default: []
187
    packages:
188
      - github.com/jmoiron/sqlx
189

190
  tenv:
191
    # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
192
    # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
193
    # Default: false
194
    all: true
195

196

197
linters:
198
  disable-all: true
199
  enable:
200
    ## enabled by default
201
    - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
202
    - gosimple # specializes in simplifying a code
203
    - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
204
    - ineffassign # detects when assignments to existing variables are not used
205
    - staticcheck # is a go vet on steroids, applying a ton of static analysis checks
206
    - typecheck # like the front-end of a Go compiler, parses and type-checks Go code
207
    - unused # checks for unused constants, variables, functions and types
208
    ## disabled by default
209
    - asasalint # checks for pass []any as any in variadic func(...any)
210
    - asciicheck # checks that your code does not contain non-ASCII identifiers
211
    - bidichk # checks for dangerous unicode character sequences
212
    - bodyclose # checks whether HTTP response body is closed successfully
213
    - cyclop # checks function and package cyclomatic complexity
214
    - dupl # tool for code clone detection
215
    - durationcheck # checks for two durations multiplied together
216
    - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
217
    - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
218
    - execinquery # checks query string in Query function which reads your Go src files and warning it finds
219
    - exhaustive # checks exhaustiveness of enum switch statements
220
    - exportloopref # checks for pointers to enclosing loop variables
221
    - forbidigo # forbids identifiers
222
    - funlen # tool for detection of long functions
223
    - gocheckcompilerdirectives # validates go compiler directive comments (//go:)
224
    - gochecknoglobals # checks that no global variables exist
225
    - gochecknoinits # checks that no init functions are present in Go code
226
    - gochecksumtype # checks exhaustiveness on Go "sum types"
227
    - gocognit # computes and checks the cognitive complexity of functions
228
    - goconst # finds repeated strings that could be replaced by a constant
229
    - gocritic # provides diagnostics that check for bugs, performance and style issues
230
    - gocyclo # computes and checks the cyclomatic complexity of functions
231
    - godot # checks if comments end in a period
232
    - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
233
    - gomnd # detects magic numbers
234
    - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
235
    - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
236
    - goprintffuncname # checks that printf-like functions are named with f at the end
237
    - gosec # inspects source code for security problems
238
    - lll # reports long lines
239
    - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
240
    - makezero # finds slice declarations with non-zero initial length
241
    - mirror # reports wrong mirror patterns of bytes/strings usage
242
    - musttag # enforces field tags in (un)marshaled structs
243
    - nakedret # finds naked returns in functions greater than a specified function length
244
    - nestif # reports deeply nested if statements
245
    - nilerr # finds the code that returns nil even if it checks that the error is not nil
246
    - nilnil # checks that there is no simultaneous return of nil error and an invalid value
247
    - noctx # finds sending http request without context.Context
248
    - nolintlint # reports ill-formed or insufficient nolint directives
249
    - nonamedreturns # reports all named returns
250
    - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
251
    - perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative
252
    - predeclared # finds code that shadows one of Go's predeclared identifiers
253
    - promlinter # checks Prometheus metrics naming via promlint
254
    - protogetter # reports direct reads from proto message fields when getters should be used
255
    - reassign # checks that package variables are not reassigned
256
    - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
257
    - rowserrcheck # checks whether Err of rows is checked successfully
258
    - sloglint # ensure consistent code style when using log/slog
259
    - spancheck # checks for mistakes with OpenTelemetry/Census spans
260
    - sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
261
    - stylecheck # is a replacement for golint
262
    - tenv # detects using os.Setenv instead of t.Setenv since Go1.17
263
    - testableexamples # checks if examples are testable (have an expected output)
264
    - testifylint # checks usage of github.com/stretchr/testify
265
    #    - testpackage # makes you use a separate _test package
266
    - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
267
    - unconvert # removes unnecessary type conversions
268
    - unparam # reports unused function parameters
269
    - usestdlibvars # detects the possibility to use variables/constants from the Go standard library
270
    - wastedassign # finds wasted assignment statements
271
    - whitespace # detects leading and trailing whitespace
272

273
    ## you may want to enable
274
    #- decorder # checks declaration order and count of types, constants, variables and functions
275
    #- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized
276
    #- gci # controls golang package import order and makes it always deterministic
277
    #- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
278
    #- godox # detects FIXME, TODO and other comment keywords
279
    #- goheader # checks is file header matches to pattern
280
    #- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters
281
    #- interfacebloat # checks the number of methods inside an interface
282
    #- ireturn # accept interfaces, return concrete types
283
    #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
284
    #- tagalign # checks that struct tags are well aligned
285
    #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
286
    #- wrapcheck # checks that errors returned from external packages are wrapped
287
    #- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event
288

289
    ## disabled
290
    #- containedctx # detects struct contained context.Context field
291
    #- contextcheck # [too many false positives] checks the function whether use a non-inherited context
292
    #- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
293
    #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
294
    #- dupword # [useless without config] checks for duplicate words in the source code
295
    #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted
296
    #- forcetypeassert # [replaced by errcheck] finds forced type assertions
297
    #- goerr113 # [too strict] checks the errors handling expressions
298
    #- gofmt # [replaced by goimports] checks whether code was gofmt-ed
299
    #- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
300
    #- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase
301
    #- grouper # analyzes expression groups
302
    #- importas # enforces consistent import aliases
303
    #- maintidx # measures the maintainability index of each function
304
    #- misspell # [useless] finds commonly misspelled English words in comments
305
    #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
306
    #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
307
    #- tagliatelle # checks the struct tags
308
    #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
309
    #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
310

311
    ## deprecated
312
    #- deadcode # [deprecated, replaced by unused] finds unused code
313
    #- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized
314
    #- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
315
    #- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible
316
    #- interfacer # [deprecated] suggests narrower interface types
317
    #- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted
318
    #- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name
319
    #- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs
320
    #- structcheck # [deprecated, replaced by unused] finds unused struct fields
321
    #- varcheck # [deprecated, replaced by unused] finds unused global variables and constants
322

323

324
issues:
325
  # Maximum count of issues with the same text.
326
  # Set to 0 to disable.
327
  # Default: 3
328
  max-same-issues: 50
329

330
  exclude-rules:
331
    - source: "(noinspection|TODO)"
332
      linters: [ godot ]
333
    - source: "//noinspection"
334
      linters: [ gocritic ]
335
    - path: "_test\\.go"
336
      linters:
337
        - bodyclose
338
        - dupl
339
        - funlen
340
        - goconst
341
        - gosec
342
        - noctx
343
        - wrapcheck
344
    # TODO: remove after PR is released https://github.com/golangci/golangci-lint/pull/4386
345
    - text: "fmt.Sprintf can be replaced with string addition"
346
      linters: [ perfsprint ]

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.