Skip to content

Commit fcef824

Browse files
authored
docs: improve linters page (#1995)
* TOC level 3 * drop `.golangci.yaml` from the Configuration page * generate a dedicated configuration section for each linters. * fix changelog heading
1 parent 874304d commit fcef824

File tree

11 files changed

+86
-25
lines changed

11 files changed

+86
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Follow the news and releases on our [twitter](https://twitter.com/golangci) and our [blog](https://medium.com/golangci).
22
There is the most valuable changes log:
33

4-
## May 2021
4+
### May 2021
55

66
1. new linters:
77
* `tagliatelle`: https://github.com/ldez/tagliatelle
@@ -25,7 +25,7 @@ There is the most valuable changes log:
2525
* set the minimum Go version to go1.15
2626
* non-zero exit code when a linter produces a panic
2727

28-
## April 2021
28+
### April 2021
2929

3030
1. new linters:
3131
* `tagliatelle`: https://github.com/ldez/tagliatelle
@@ -46,7 +46,7 @@ There is the most valuable changes log:
4646
4. Misc:
4747
* fix: comma in exclude pattern leads to unexpected results
4848

49-
## March 2021
49+
### March 2021
5050

5151
1. new linters:
5252
* `gomoddirectives`: https://github.com/ldez/gomoddirectives
@@ -76,7 +76,7 @@ There is the most valuable changes log:
7676
* fix linters load mode
7777
* Restore fast linters meaning
7878

79-
## February 2021
79+
### February 2021
8080

8181
1. new linters:
8282
* `durationcheck`: https://github.com/charithe/durationcheck
@@ -124,7 +124,7 @@ There is the most valuable changes log:
124124
* update deprecated hyperlink for Sublime Text plugin
125125
* add docs on using homebrew tap
126126

127-
## January 2021
127+
### January 2021
128128

129129
1. new linters:
130130
* `predeclared`: https://github.com/nishanths/predeclared
@@ -144,7 +144,7 @@ There is the most valuable changes log:
144144
4. documentation:
145145
* bump documentation dependencies
146146

147-
## December 2020
147+
### December 2020
148148

149149
1. new linters:
150150
* `forbidigo`: https://github.com/ashanbrown/forbidigo

docs/src/@rocketseat/gatsby-theme-docs/src/components/Docs/TOC/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ export default function TableOfContents({ headings }) {
1313
<nav>
1414
<ul>
1515
{headings
16-
.filter(heading => heading.depth === 2)
16+
.filter((heading) => heading.depth === 2 || heading.depth === 3)
1717
.map(heading => (
18-
<li key={heading.value}>
18+
<li
19+
key={heading.value}
20+
style={{
21+
marginLeft: heading.depth === 3 ? `8px` : null,
22+
}}
23+
>
1924
<a href={`#${slug(heading.value)}`}>{heading.value}</a>
2025
</li>
2126
))}

docs/src/docs/usage/configuration.mdx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ config file with all supported options, their description and default value:
4848
{ .GolangciYamlExample }
4949
```
5050

51-
It's a [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) config file of this repo: we enable more linters
52-
than the default and have more strict settings:
53-
54-
```yaml
55-
{ .GolangciYaml }
56-
```
57-
5851
## Cache
5952

6053
GolangCI-Lint stores its cache in the [default user cache directory](https://golang.org/pkg/os/#UserCacheDir).

docs/src/docs/usage/linters.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ golangci-lint help linters
1515
## Disabled By Default Linters (`-E/--enable`)
1616

1717
{.DisabledByDefaultLinters}
18+
19+
## Linters Configuration
20+
21+
{ .LintersExample }

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ require (
8383
github.com/valyala/quicktemplate v1.6.3
8484
github.com/yeya24/promlinter v0.1.0
8585
golang.org/x/tools v0.1.2-0.20210512205948-8287d5da45e4
86-
gopkg.in/yaml.v2 v2.4.0
86+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
8787
honnef.co/go/tools v0.1.4
8888
mvdan.cc/gofumpt v0.1.1
8989
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed

go.sum

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/expand_website_templates/main.go

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"sort"
1717
"strings"
1818

19+
"gopkg.in/yaml.v3"
20+
1921
"github.com/golangci/golangci-lint/internal/renameio"
2022
"github.com/golangci/golangci-lint/pkg/lint/linter"
2123
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
@@ -158,12 +160,12 @@ func getLatestVersion() (string, error) {
158160
}
159161

160162
func buildTemplateContext() (map[string]string, error) {
161-
golangciYaml, err := ioutil.ReadFile(".golangci.yml")
163+
golangciYamlExample, err := ioutil.ReadFile(".golangci.example.yml")
162164
if err != nil {
163-
return nil, fmt.Errorf("can't read .golangci.yml: %s", err)
165+
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
164166
}
165167

166-
golangciYamlExample, err := ioutil.ReadFile(".golangci.example.yml")
168+
lintersCfg, err := getLintersConfiguration(golangciYamlExample)
167169
if err != nil {
168170
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
169171
}
@@ -200,7 +202,7 @@ func buildTemplateContext() (map[string]string, error) {
200202
}
201203

202204
return map[string]string{
203-
"GolangciYaml": strings.TrimSpace(string(golangciYaml)),
205+
"LintersExample": lintersCfg,
204206
"GolangciYamlExample": strings.TrimSpace(string(golangciYamlExample)),
205207
"LintersCommandOutputEnabledOnly": string(lintersOutParts[0]),
206208
"LintersCommandOutputDisabledOnly": string(lintersOutParts[1]),
@@ -314,3 +316,59 @@ func getThanksList() string {
314316

315317
return strings.Join(lines, "\n")
316318
}
319+
320+
func getLintersConfiguration(example []byte) (string, error) {
321+
builder := &strings.Builder{}
322+
323+
var data yaml.Node
324+
err := yaml.Unmarshal(example, &data)
325+
if err != nil {
326+
return "", err
327+
}
328+
329+
root := data.Content[0]
330+
331+
for j, node := range root.Content {
332+
if node.Value != "linters-settings" {
333+
continue
334+
}
335+
336+
nodes := root.Content[j+1]
337+
338+
for i := 0; i < len(nodes.Content); i += 2 {
339+
r := &yaml.Node{
340+
Kind: nodes.Kind,
341+
Style: nodes.Style,
342+
Tag: nodes.Tag,
343+
Value: node.Value,
344+
Content: []*yaml.Node{
345+
{
346+
Kind: root.Content[j].Kind,
347+
Value: root.Content[j].Value,
348+
},
349+
{
350+
Kind: nodes.Kind,
351+
Content: []*yaml.Node{nodes.Content[i], nodes.Content[i+1]},
352+
},
353+
},
354+
}
355+
356+
_, _ = fmt.Fprintf(builder, "### %s\n\n", nodes.Content[i].Value)
357+
_, _ = fmt.Fprintln(builder, "```yaml")
358+
359+
const ident = 2
360+
encoder := yaml.NewEncoder(builder)
361+
encoder.SetIndent(ident)
362+
363+
err = encoder.Encode(r)
364+
if err != nil {
365+
return "", err
366+
}
367+
368+
_, _ = fmt.Fprintln(builder, "```")
369+
_, _ = fmt.Fprintln(builder)
370+
}
371+
}
372+
373+
return builder.String(), nil
374+
}

test/fix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99

1010
"github.com/stretchr/testify/require"
11-
yaml "gopkg.in/yaml.v2"
11+
"gopkg.in/yaml.v3"
1212

1313
"github.com/golangci/golangci-lint/test/testshared"
1414
)

test/linters_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/stretchr/testify/require"
13-
"gopkg.in/yaml.v2"
13+
"gopkg.in/yaml.v3"
1414

1515
"github.com/golangci/golangci-lint/pkg/exitcodes"
1616
"github.com/golangci/golangci-lint/test/testshared"

test/testdata/configs/gomodguard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ linters-settings:
55
- golang.org/x/mod/modfile
66
blocked:
77
modules: # List of blocked modules
8-
- gopkg.in/yaml.v2: # Blocked module
8+
- gopkg.in/yaml.v3: # Blocked module
99
recommendations: # Recommended modules that should be used instead (Optional)
1010
- github.com/kylelemons/go-gypsy
1111
reason: "This is an example of recommendations." # Reason why the recommended module should be used (Optional)

test/testdata/gomodguard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77

88
"golang.org/x/mod/modfile"
9-
"gopkg.in/yaml.v2" // ERROR "import of package `gopkg.in/yaml.v2` is blocked because the module is in the blocked modules list. `github.com/kylelemons/go-gypsy` is a recommended module. This is an example of recommendations."
9+
"gopkg.in/yaml.v3" // ERROR "import of package `gopkg.in/yaml.v3` is blocked because the module is in the blocked modules list. `github.com/kylelemons/go-gypsy` is a recommended module. This is an example of recommendations."
1010
)
1111

1212
// Something just some struct

0 commit comments

Comments
 (0)