2023-07-18 08:16:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-08-07 14:24:19 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2023-07-31 09:59:51 +00:00
|
|
|
noliteral "git.frostfs.info/TrueCloudLab/linters/internal/analyzers/noliteral"
|
2023-08-01 11:39:49 +00:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2023-07-18 08:16:27 +00:00
|
|
|
"golang.org/x/tools/go/analysis"
|
|
|
|
)
|
|
|
|
|
|
|
|
var AnalyzerPlugin analyzerPlugin
|
|
|
|
|
|
|
|
type analyzerPlugin struct{}
|
|
|
|
|
2023-08-01 11:39:49 +00:00
|
|
|
// for version ci-lint < '1.5.4'.
|
2023-07-18 08:16:27 +00:00
|
|
|
func (*analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {
|
2023-08-07 14:24:19 +00:00
|
|
|
analyzer, _ := New(nil)
|
|
|
|
return analyzer
|
2023-07-18 08:16:27 +00:00
|
|
|
}
|
2023-08-01 11:39:49 +00:00
|
|
|
|
|
|
|
// for version ci-lint >= '1.5.4'.
|
|
|
|
func New(conf any) ([]*analysis.Analyzer, error) {
|
2023-08-07 14:24:19 +00:00
|
|
|
targetMethods := strings.Split(os.Getenv("NOLITERAL_TARGET_METHODS"), ",")
|
2023-08-07 14:36:41 +00:00
|
|
|
disablePackages := strings.Split(os.Getenv("NOLITERAL_DISABLE_PACKAGES"), ",")
|
2023-08-07 14:24:19 +00:00
|
|
|
constantsPackage := os.Getenv("NOLITERAL_CONSTANTS_PACKAGE")
|
|
|
|
|
|
|
|
configMap := map[string]any{
|
|
|
|
"target-methods": targetMethods,
|
|
|
|
"constants-package": constantsPackage,
|
2023-08-07 14:36:41 +00:00
|
|
|
"disable-packages": disablePackages,
|
2023-08-07 14:24:19 +00:00
|
|
|
}
|
2023-08-01 11:39:49 +00:00
|
|
|
|
|
|
|
if confMap, ok := conf.(map[string]any); ok {
|
2023-08-07 14:24:19 +00:00
|
|
|
for k, v := range confMap {
|
|
|
|
configMap[k] = v
|
2023-08-01 11:39:49 +00:00
|
|
|
}
|
2023-08-07 14:24:19 +00:00
|
|
|
}
|
2023-08-01 11:39:49 +00:00
|
|
|
|
2023-08-07 14:24:19 +00:00
|
|
|
var config noliteral.Configuration
|
|
|
|
err := mapstructure.Decode(configMap, &config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-08-01 11:39:49 +00:00
|
|
|
}
|
|
|
|
|
2023-08-07 14:24:19 +00:00
|
|
|
noliteral.Config.TargetMethods = append(noliteral.Config.TargetMethods, config.TargetMethods...)
|
|
|
|
noliteral.Config.ConstantsPackage = config.ConstantsPackage
|
2023-08-07 14:36:41 +00:00
|
|
|
noliteral.Config.DisablePackages = config.DisablePackages
|
2023-08-07 14:24:19 +00:00
|
|
|
|
2023-08-01 11:39:49 +00:00
|
|
|
return []*analysis.Analyzer{noliteral.LogsAnalyzer}, nil
|
|
|
|
}
|