Skip to content

Commit bdc2f96

Browse files
Add code comments to document source code (#2306)
1 parent 00e4770 commit bdc2f96

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

pkg/commands/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func (e *Executor) initConfig() {
3535
cmd.AddCommand(pathCmd)
3636
}
3737

38+
// getUsedConfig returns the resolved path to the golangci config file, or the empty string
39+
// if no configuration could be found.
3840
func (e *Executor) getUsedConfig() string {
3941
usedConfigFile := viper.ConfigFileUsed()
4042
if usedConfigFile == "" {

pkg/commands/executor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Executor struct {
3838
exitCode int
3939
version, commit, date string
4040

41-
cfg *config.Config
41+
cfg *config.Config // cfg is the unmarshaled data from the golangci config file.
4242
log logutils.Log
4343
reportData report.Data
4444
DBManager *lintersdb.Manager

pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package config
22

3+
// Config encapsulates the config data specified in the golangci yaml config file.
34
type Config struct {
45
Run Run
56

pkg/config/linters_settings.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,20 @@ type WSLSettings struct {
501501
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
502502
}
503503

504+
// CustomLinterSettings encapsulates the meta-data of a private linter.
505+
// For example, a private linter may be added to the golangci config file as shown below.
506+
//
507+
// linters-settings:
508+
// custom:
509+
// example:
510+
// path: /example.so
511+
// description: The description of the linter
512+
// original-url: github.com/golangci/example-linter
504513
type CustomLinterSettings struct {
505-
Path string
514+
// Path to a plugin *.so file that implements the private linter.
515+
Path string
516+
// Description describes the purpose of the private linter.
506517
Description string
518+
// The URL containing the source code for the private linter.
507519
OriginalURL string `mapstructure:"original-url"`
508520
}

pkg/config/run.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import "time"
44

5+
// Run encapsulates the config options for running the linter analysis.
56
type Run struct {
67
IsVerbose bool `mapstructure:"verbose"`
78
Silent bool

pkg/lint/lintersdb/manager.go

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func NewManager(cfg *config.Config, log logutils.Log) *Manager {
3535
return m
3636
}
3737

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

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

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

0 commit comments

Comments
 (0)