diff options
author | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2023-08-22 13:09:54 +0300 |
---|---|---|
committer | Quang-Minh Nguyen <qmnguyen@gitlab.com> | 2023-08-22 13:09:54 +0300 |
commit | 548364de5404ed0be6b36416fc7ba4a49a236819 (patch) | |
tree | defb6ae69d48f9ed067226e44c490a9d5ae92ca8 | |
parent | 618ce167cb411483c21ca3be8399f57157cc81ae (diff) | |
parent | 11ad5736e25316c90ec563e2367d7b745fa1b37e (diff) |
Merge branch 'wc/update-to-new-linter-api' into 'master'
Linter: Update to new customer linter API
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6246
Merged-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Approved-by: Quang-Minh Nguyen <qmnguyen@gitlab.com>
Co-authored-by: Will Chandler <wchandler@gitlab.com>
-rw-r--r-- | tools/golangci-lint/gitaly/lint.go | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/tools/golangci-lint/gitaly/lint.go b/tools/golangci-lint/gitaly/lint.go index 3b4f64232..0d49db4ed 100644 --- a/tools/golangci-lint/gitaly/lint.go +++ b/tools/golangci-lint/gitaly/lint.go @@ -7,31 +7,30 @@ import ( "golang.org/x/tools/go/analysis" ) -type analyzerPlugin struct{} - -func (p *analyzerPlugin) GetAnalyzers() []*analysis.Analyzer { +// New initializes Gitaly's custom linters. +func New(conf any) ([]*analysis.Analyzer, error) { return []*analysis.Analyzer{ newQuoteInterpolationAnalyzer("eInterpolationAnalyzerSettings{ - IncludedFunctions: p.configStringSlicesAt( + IncludedFunctions: configStringSlicesAt( quoteInterpolationAnalyzerName, "included-functions", ), }), newErrorWrapAnalyzer(&errorWrapAnalyzerSettings{ - IncludedFunctions: p.configStringSlicesAt( + IncludedFunctions: configStringSlicesAt( errorWrapAnalyzerName, "included-functions", ), }), - newUnavailableCodeAnalyzer(&unavailableCodeAnalyzerSettings{IncludedFunctions: p.configStringSlicesAt( + newUnavailableCodeAnalyzer(&unavailableCodeAnalyzerSettings{IncludedFunctions: configStringSlicesAt( unavailableCodeAnalyzerName, "included-functions", )}), newTestParamsOrder(), - } + }, nil } -// This method fetches a string slices in golangci-lint config files for the input analyzer. This is +// This function fetches a string slices in golangci-lint config files for the input analyzer. This is // an enhancement to golangci-lint. Although it supports custom linters, it doesn't support parsing // custom settings for such linters. We have to take care of parsing ourselves. Fortunately, // golangci-lint uses `viper` package underlying. This package maintains a global process state. @@ -61,7 +60,7 @@ func (p *analyzerPlugin) GetAnalyzers() []*analysis.Analyzer { // - gitlab.com/gitlab-org/gitaly/v15/internal/structerr.* // // ``` -func (*analyzerPlugin) configStringSlicesAt(analyzer string, key string) []string { +func configStringSlicesAt(analyzer string, key string) []string { path := strings.Join([]string{ "linters-settings", "custom", @@ -72,13 +71,3 @@ func (*analyzerPlugin) configStringSlicesAt(analyzer string, key string) []strin }, ".") return viper.GetStringSlice(path) } - -// AnalyzerPlugin is a convention of golangci-lint to implement a custom linter. This variable -// must implement `AnalyzerPlugin` interface: -// -// type AnalyzerPlugin interface { -// GetAnalyzers() []*analysis.Analyzer -// } -// -// For more information, please visit https://golangci-lint.run/contributing/new-linters/ -var AnalyzerPlugin analyzerPlugin |