Skip to content

Commit d2a825e

Browse files
committed
doc: update some pages
1 parent a701970 commit d2a825e

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

docs/src/docs/contributing/architecture.mdx

+17-17
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ The linter database (`linterdb.Manager`) is fill based on the configuration:
3333
## Load Packages
3434

3535
Loading packages is listing all packages and their recursive dependencies for analysis.
36-
Also, depending on the enabled linters set some parsing of the source code can be performed
37-
at this step.
36+
Also, depending on the enabled linters set some parsing of the source code can be performed at this step.
3837

3938
Packages loading starts here:
4039

@@ -87,10 +86,10 @@ and outputs list of packages and requested information about them: filenames, ty
8786

8887
First, we need to find all enabled linters. All linters are registered here:
8988

90-
```go title=pkg/lint/lintersdb/manager.go
91-
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
89+
```go title=pkg/lint/lintersdb/builder_linter.go
90+
func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config {
9291
// ...
93-
linters = append(linters,
92+
return []*linter.Config{
9493
// ...
9594
linter.NewConfig(golinters.NewBodyclose()).
9695
WithSince("v1.18.0").
@@ -105,26 +104,25 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
105104
WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
106105
WithAlternativeNames("vet", "vetshadow").
107106
WithURL("https://pkg.go.dev/cmd/vet"),
107+
// ...
108108
}
109-
// ...
110109
}
111110
```
112111

113112
We filter requested in config and command-line linters in `EnabledSet`:
114113

115-
```go title=pkg/lint/lintersdb/enabled_set.go
116-
func (es EnabledSet) GetEnabledLintersMap() (map[string]*linter.Config, error)
114+
```go title=pkg/lint/lintersdb/manager.go
115+
func (m *Manager) GetEnabledLintersMap() (map[string]*linter.Config, error)
117116
```
118117

119118
We merge enabled linters into one `MetaLinter` to improve execution time if we can:
120119

121-
```go title=pkg/lint/lintersdb/enabled_set.go
122-
// GetOptimizedLinters returns enabled linters after optimization (merging) of multiple linters
123-
// into a fewer number of linters. E.g. some go/analysis linters can be optimized into
124-
// one metalinter for data reuse and speed up.
125-
func (es EnabledSet) GetOptimizedLinters() ([]*linter.Config, error) {
120+
```go titlepkg/lint/lintersdb/manager.go
121+
// GetOptimizedLinters returns enabled linters after optimization (merging) of multiple linters into a fewer number of linters.
122+
// E.g. some go/analysis linters can be optimized into one metalinter for data reuse and speed up.
123+
func (m *Manager) GetOptimizedLinters() ([]*linter.Config, error) {
126124
// ...
127-
es.combineGoAnalysisLinters(resultLintersSet)
125+
m.combineGoAnalysisLinters(resultLintersSet)
128126
// ...
129127
}
130128
```
@@ -141,9 +139,11 @@ type MetaLinter struct {
141139
Currently, all linters except `unused` can be merged into this meta linter.
142140
The `unused` isn't merged because it has high memory usage.
143141

144-
Linters execution starts in `runAnalyzers`. It's the most complex part of the `golangci-lint`.
145-
We use custom [go/analysis](https://pkg.go.dev/golang.org/x/tools/go/analysis) runner there. It runs as much as it can in parallel. It lazy-loads as much as it can
146-
to reduce memory usage. Also, it sets all heavyweight data to `nil` as becomes unneeded to save memory.
142+
Linters execution starts in `runAnalyzers`.
143+
It's the most complex part of the `golangci-lint`.
144+
We use custom [go/analysis](https://pkg.go.dev/golang.org/x/tools/go/analysis) runner there.
145+
It runs as much as it can in parallel. It lazy-loads as much as it can to reduce memory usage.
146+
Also, it sets all heavyweight data to `nil` as becomes unneeded to save memory.
147147

148148
We don't use existing [multichecker](https://pkg.go.dev/golang.org/x/tools/go/analysis/multichecker) because
149149
it doesn't use caching and doesn't have some important performance optimizations.

docs/src/docs/contributing/new-linters.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ After that:
2828
Look at other linters in this directory.
2929
Implement linter integration and check that test passes.
3030
3. Add the new struct for the linter (which you've implemented in `pkg/golinters/{yourlintername}.go`) to the
31-
list of all supported linters in [`pkg/lint/lintersdb/manager.go`](https://github.com/golangci/golangci-lint/blob/master/pkg/lint/lintersdb/manager.go)
32-
to the function `GetAllSupportedLinterConfigs`.
31+
list of all supported linters in [`pkg/lint/lintersdb/builder_linter.go`](https://github.com/golangci/golangci-lint/blob/masterpkg/lint/lintersdb/builder_linter.go)
32+
to the method `LinterBuilder.Build`.
3333
- Add `WithSince("next_version")`, where `next_version` must be replaced by the next minor version. (ex: v1.2.0 if the current version is v1.1.0)
3434
4. Find out what options do you need to configure for the linter.
3535
For example, `nakedret` has only 1 option: [`max-func-lines`](https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml).

pkg/lint/lintersdb/manager.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ func (m *Manager) GetEnabledLintersMap() (map[string]*linter.Config, error) {
9898
return enabledLinters, nil
9999
}
100100

101-
// GetOptimizedLinters returns enabled linters after optimization (merging) of multiple linters
102-
// into a fewer number of linters. E.g. some go/analysis linters can be optimized into
103-
// one metalinter for data reuse and speed up.
101+
// GetOptimizedLinters returns enabled linters after optimization (merging) of multiple linters into a fewer number of linters.
102+
// E.g. some go/analysis linters can be optimized into one metalinter for data reuse and speed up.
104103
func (m *Manager) GetOptimizedLinters() ([]*linter.Config, error) {
105104
resultLintersSet := m.build(m.GetAllEnabledByDefaultLinters())
106105
m.verbosePrintLintersStatus(resultLintersSet)

0 commit comments

Comments
 (0)