-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Steps to reproduce
- build the plugin
- copy to your project folder
- setup a config, like this:
linters-settings:
custom:
nilaway:
path: ./bin/nilaway.so
description: self-built nilaway plugin
original-url: github.com/nilaway-plugin
settings:
pretty-print: false
- run
golangci-lint run --disable-all -E nilaway
- no errors will be thrown but
pretty-print
is not actually disabled.--include-pkgs
won't work etiher.
Reason
This is happening because the config isn't read by the plugin.New()
func New(conf any) ([]*analysis.Analyzer, error) {
return []*analysis.Analyzer{nilaway.Analyzer}, nil
}
Part of the solution is to take this conf any
and turn it into a map[string]any
, then read key value pairs from there and feed them into the analyzer flag sets. However, it's more complicated than that.
nilaway has a multi-tiered architecture, where the config needs to actually be read by a separate analyzer that all analyzers are dependent on, called 'nilaway_config'
To address this problem, we have defined a separate "nilaway_config" analyzer which is only responsible for defining the Flags field and expose the configs through its return value. All other sub-analyzers will depend on the config.Analyzer and use the values there to execute different logic.
Reference
- config analyzer - https://github.com/uber-go/nilaway/blob/71d1444e6bfec82bb7573ecadf12505a78d4f532/config/config.go#L110-L119
- nilaway main analyzer - https://github.com/uber-go/nilaway/blob/71d1444e6bfec82bb7573ecadf12505a78d4f532/nilaway.go#L36
- nilaway wiki on passing configs - https://github.com/uber-go/nilaway/wiki/Configuration#passing-configurations
Solution
We need to also build nilaway_analyzer.so somehow.
The YAML config will need to look more like:
run:
timeout: 2m
linters-settings:
custom:
nilaway_config:
path: ./bin/nilaway_config.so
description: self-built nilaway plugin
original-url: github.com/nilaway_config-plugin
settings:
pretty-print: false
nilaway:
path: ./bin/nilaway.so
description: self-built nilaway plugin
original-url: github.com/nilaway-plugin
# like the nilaway/golangci-custom linter docs mention, you apply the golangci-related stuff (like excludes) on nilaway, but the actual flag setting gets done on nilaway_analyzer
issues:
exclude-rules:
- linters:
- nilaway
path: "cmd/terraform.go"