[英]golangci-lint - want to "really" ignore a go file not simply analyse it and suppress warnings - my current ignore approach eats memory and is slow
使用golangci-lint
我知道我可以使用skip-dirs
或skip-files
设置,但这些只是在最后停止报告,我认为该工具仍然可以“工作”,引用文档:
...要跳过哪些文件:它们将被分析,但不会报告它们的问题。 ...
有没有办法,比如使用//nolint
的变体来防止某些文件首先被golangci-lint
分析,这样我们就不会浪费构建时资源 - 内存/cpu - 在它们上面?
我还尝试了顶部的行,例如// Code generated by XXX. DO NOT EDIT.
// Code generated by XXX. DO NOT EDIT.
和这些类似//nolint
停止报告但我认为golangci-lint
仍在进行分析 - 即当存在大的“被忽略”文件时,工具在高内存的情况下运行缓慢。 从https://github.com/golangci/golangci-lint#nolint我可以做到
> //nolint:unparam
> package pkg
确实没有报告任何 lint 错误,但我仍然使用过多的内存,例如
13:14 $ golangci-lint run --timeout 30m -v
INFO [config_reader] Config search paths: [ REMOVED FOR STACKOVERFLOW POST]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 17 linters: [deadcode dogsled errcheck gocyclo golint gosimple govet ineffassign misspell nakedret scopelint staticcheck structcheck typecheck unconvert unused varcheck]
INFO [lintersdb] Active 17 linters: [deadcode dogsled errcheck gocyclo golint gosimple govet ineffassign misspell nakedret scopelint staticcheck structcheck typecheck unconvert unused varcheck]
INFO [loader] Go packages loading at mode 575 (deps|imports|name|types_sizes|compiled_files|exports_file|files) took 15.003932542s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 831.549179ms
INFO [runner/unused/goanalysis] analyzers took 15.395924718s with top 10 stages: U1000: 13.12191427s, buildssa: 2.274010448s
INFO [runner/goanalysis_metalinter/goanalysis] analyzers took 8m25.344883444s with top 10 stages: golint: 6m29.017594865s, ineffassign: 50.003663795s, vrp: 34.694968113s, misspell: 5.91752885s, buildssa: 4.09136586s, SA2003: 1.003697913s, copylocks: 660.780161ms, SA4000: 601.476823ms, SA4018: 510.871677ms, SA4004: 476.466048ms
INFO [runner] Issues before processing: 28876, after processing: 0
INFO [runner] Processors filtering stat (out/in): skip_files: 28876/28876, skip_dirs: 28876/28876, identifier_marker: 53/53, path_prettifier: 28876/28876, autogenerated_exclude: 53/28876, exclude: 0/53, filename_unadjuster: 28876/28876, cgo: 28876/28876
INFO [runner] processing took 60.293318ms with stages: autogenerated_exclude: 33.592255ms, path_prettifier: 18.17708ms, skip_dirs: 4.421717ms, filename_unadjuster: 1.497968ms, cgo: 1.333012ms, identifier_marker: 1.036647ms, exclude: 220.939µs, nolint: 8.996µs, max_same_issues: 1.448µs, uniq_by_line: 592ns, exclude-rules: 544ns, max_from_linter: 467ns, skip_files: 386ns, diff: 362ns, path_shortener: 331ns, source_code: 309ns, max_per_file_from_linter: 265ns
INFO [runner] linters took 6m47.422489108s with stages: goanalysis_metalinter: 6m28.298523575s, unused: 19.033707326s
INFO File cache stats: 2 entries of total size 40.4MiB
INFO Memory: 4114 samples, avg is 7797.4MB, max is 8629.2MB
INFO Execution took 7m3.337365705s
当我删除大文件时,golangci-lint 表现良好。
使用新的构建标签来排除golangci-lint
文件实际上减少了它的内存消耗(通过阻止解析文件)
以下示例基于: https : //android.googlesource.com/platform/external/syzkaller/+/01d1494471798d6b91af9813d1d6c3e13a55536c
现在将“有效”跳过的 Go 文件
// AUTOGENERATED FILE
// +build !codeanalysis
package foo
.golangci.yml
run:
deadline: 8m
skip-dirs:
- pkg/kd
# Autogenerated files take too much time and memory to load,
# even if we skip them with skip-dirs.
# So we define this tag and use it in the autogenerated files.
build-tags:
- codeanalysis
我已经用我的设置对此进行了简要测试,并且该工具不再占用大量内存,与以下方法不同......
//nolint
// Code generated by XXX. DO NOT EDIT.
生成显示文件的行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.