Add code comments to document source code (#2306)
This commit is contained in:
parent
00e477026f
commit
bdc2f96de9
@ -35,6 +35,8 @@ func (e *Executor) initConfig() {
|
|||||||
cmd.AddCommand(pathCmd)
|
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 {
|
func (e *Executor) getUsedConfig() string {
|
||||||
usedConfigFile := viper.ConfigFileUsed()
|
usedConfigFile := viper.ConfigFileUsed()
|
||||||
if usedConfigFile == "" {
|
if usedConfigFile == "" {
|
||||||
|
@ -38,7 +38,7 @@ type Executor struct {
|
|||||||
exitCode int
|
exitCode int
|
||||||
version, commit, date string
|
version, commit, date string
|
||||||
|
|
||||||
cfg *config.Config
|
cfg *config.Config // cfg is the unmarshaled data from the golangci config file.
|
||||||
log logutils.Log
|
log logutils.Log
|
||||||
reportData report.Data
|
reportData report.Data
|
||||||
DBManager *lintersdb.Manager
|
DBManager *lintersdb.Manager
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
// Config encapsulates the config data specified in the golangci yaml config file.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Run Run
|
Run Run
|
||||||
|
|
||||||
|
@ -501,8 +501,20 @@ type WSLSettings struct {
|
|||||||
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
|
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 {
|
type CustomLinterSettings struct {
|
||||||
|
// Path to a plugin *.so file that implements the private linter.
|
||||||
Path string
|
Path string
|
||||||
|
// Description describes the purpose of the private linter.
|
||||||
Description string
|
Description string
|
||||||
|
// The URL containing the source code for the private linter.
|
||||||
OriginalURL string `mapstructure:"original-url"`
|
OriginalURL string `mapstructure:"original-url"`
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
// Run encapsulates the config options for running the linter analysis.
|
||||||
type Run struct {
|
type Run struct {
|
||||||
IsVerbose bool `mapstructure:"verbose"`
|
IsVerbose bool `mapstructure:"verbose"`
|
||||||
Silent bool
|
Silent bool
|
||||||
|
@ -35,6 +35,7 @@ func NewManager(cfg *config.Config, log logutils.Log) *Manager {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithCustomLinters loads private linters that are specified in the golangci config file.
|
||||||
func (m *Manager) WithCustomLinters() *Manager {
|
func (m *Manager) WithCustomLinters() *Manager {
|
||||||
if m.log == nil {
|
if m.log == nil {
|
||||||
m.log = report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
|
m.log = report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
|
||||||
@ -594,6 +595,8 @@ func (m Manager) GetAllLinterConfigsForPreset(p string) []*linter.Config {
|
|||||||
return ret
|
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) {
|
func (m Manager) loadCustomLinterConfig(name string, settings config.CustomLinterSettings) (*linter.Config, error) {
|
||||||
analyzer, err := m.getAnalyzerPlugin(settings.Path)
|
analyzer, err := m.getAnalyzerPlugin(settings.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -616,6 +619,11 @@ type AnalyzerPlugin interface {
|
|||||||
GetAnalyzers() []*analysis.Analyzer
|
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) {
|
func (m Manager) getAnalyzerPlugin(path string) (AnalyzerPlugin, error) {
|
||||||
if !filepath.IsAbs(path) {
|
if !filepath.IsAbs(path) {
|
||||||
// resolve non-absolute paths relative to config file's directory
|
// resolve non-absolute paths relative to config file's directory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user