Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code comments to document source code #2306

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (e *Executor) initConfig() {
cmd.AddCommand(pathCmd)
}

// getUsedConfig returns the resolved path to the golangci config file, or the empty string
// if no configuration could be found.
func (e *Executor) getUsedConfig() string {
usedConfigFile := viper.ConfigFileUsed()
if usedConfigFile == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Executor struct {
exitCode int
version, commit, date string

cfg *config.Config
cfg *config.Config // cfg is the unmarshaled data from the golangci config file.
log logutils.Log
reportData report.Data
DBManager *lintersdb.Manager
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package config

// Config encapsulates the config data specified in the golangci yaml config file.
type Config struct {
Run Run

Expand Down
14 changes: 13 additions & 1 deletion pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,20 @@ type WSLSettings struct {
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
}

// CustomLinterSettings encapsulates the meta-data of a private linter.
// For example, a private linter may be added to the golangci config file as shown below.
//
// linters-settings:
// custom:
// example:
// path: /example.so
// description: The description of the linter
// original-url: github.com/golangci/example-linter
type CustomLinterSettings struct {
Path string
// Path to a plugin *.so file that implements the private linter.
Path string
// Description describes the purpose of the private linter.
Description string
// The URL containing the source code for the private linter.
OriginalURL string `mapstructure:"original-url"`
}
1 change: 1 addition & 0 deletions pkg/config/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import "time"

// Run encapsulates the config options for running the linter analysis.
type Run struct {
IsVerbose bool `mapstructure:"verbose"`
Silent bool
Expand Down
8 changes: 8 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewManager(cfg *config.Config, log logutils.Log) *Manager {
return m
}

// WithCustomLinters loads private linters that are specified in the golangci config file.
func (m *Manager) WithCustomLinters() *Manager {
if m.log == nil {
m.log = report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
Expand Down Expand Up @@ -594,6 +595,8 @@ func (m Manager) GetAllLinterConfigsForPreset(p string) []*linter.Config {
return ret
}

// loadCustomLinterConfig loads the configuration of private linters.
// Private linters are dynamically loaded from .so plugin files.
func (m Manager) loadCustomLinterConfig(name string, settings config.CustomLinterSettings) (*linter.Config, error) {
analyzer, err := m.getAnalyzerPlugin(settings.Path)
if err != nil {
Expand All @@ -616,6 +619,11 @@ type AnalyzerPlugin interface {
GetAnalyzers() []*analysis.Analyzer
}

// getAnalyzerPlugin loads a private linter as specified in the config file,
// loads the plugin from a .so file, and returns the 'AnalyzerPlugin' interface
// implemented by the private plugin.
// An error is returned if the private linter cannot be loaded or the linter
// does not implement the AnalyzerPlugin interface.
func (m Manager) getAnalyzerPlugin(path string) (AnalyzerPlugin, error) {
if !filepath.IsAbs(path) {
// resolve non-absolute paths relative to config file's directory
Expand Down