docs: split configuration page into multiple sections (#2484)
This commit is contained in:
parent
83ff65a7e2
commit
c84de88229
@ -16,7 +16,7 @@ linters-settings:
|
|||||||
local-prefixes: github.com/golangci/golangci-lint
|
local-prefixes: github.com/golangci/golangci-lint
|
||||||
goconst:
|
goconst:
|
||||||
min-len: 2
|
min-len: 2
|
||||||
min-occurrences: 2
|
min-occurrences: 3
|
||||||
gocritic:
|
gocritic:
|
||||||
enabled-tags:
|
enabled-tags:
|
||||||
- diagnostic
|
- diagnostic
|
||||||
|
1
docs/package-lock.json
generated
1
docs/package-lock.json
generated
@ -24195,6 +24195,7 @@
|
|||||||
"version": "0.27.1",
|
"version": "0.27.1",
|
||||||
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.27.1.tgz",
|
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.27.1.tgz",
|
||||||
"integrity": "sha512-IQNXWdspb4nZcJemXa6cfgz+JvKONsuqP8Mwi1Oti23Uo7+J+UF2jihJDf6I1BQbrmhcZ0lagH/1WYG+ReAzyQ==",
|
"integrity": "sha512-IQNXWdspb4nZcJemXa6cfgz+JvKONsuqP8Mwi1Oti23Uo7+J+UF2jihJDf6I1BQbrmhcZ0lagH/1WYG+ReAzyQ==",
|
||||||
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"array-flatten": "^3.0.0",
|
"array-flatten": "^3.0.0",
|
||||||
"color": "^3.1.3",
|
"color": "^3.1.3",
|
||||||
|
@ -12,19 +12,6 @@ To see a list of enabled by your configuration linters:
|
|||||||
golangci-lint linters
|
golangci-lint linters
|
||||||
```
|
```
|
||||||
|
|
||||||
## Command-Line Options
|
|
||||||
|
|
||||||
```sh
|
|
||||||
golangci-lint run -h
|
|
||||||
{.RunHelpText}
|
|
||||||
```
|
|
||||||
|
|
||||||
When the `--cpu-profile-path` or `--mem-profile-path` arguments are specified, `golangci-lint` writes runtime profiling data
|
|
||||||
in the format expected by the [pprof](https://github.com/google/pprof) visualization tool.
|
|
||||||
|
|
||||||
When the `--trace-path` argument is specified, `golangci-lint` writes runtime tracing data in the format expected by
|
|
||||||
the `go tool trace` command and visualization tool.
|
|
||||||
|
|
||||||
## Config File
|
## Config File
|
||||||
|
|
||||||
GolangCI-Lint looks for config files in the following paths from the current working directory:
|
GolangCI-Lint looks for config files in the following paths from the current working directory:
|
||||||
@ -41,13 +28,24 @@ To see which config file is being used and where it was sourced from run golangc
|
|||||||
Config options inside the file are identical to command-line options.
|
Config options inside the file are identical to command-line options.
|
||||||
You can configure specific linters' options only within the config file (not the command-line).
|
You can configure specific linters' options only within the config file (not the command-line).
|
||||||
|
|
||||||
There is a [`.golangci.example.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) example
|
There is a [`.golangci.example.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) file with all supported options, their description, and default values.
|
||||||
config file with all supported options, their description and default value:
|
This file is a neither a working example nor recommended configuration, it's just a reference to display all the configuration options.
|
||||||
|
|
||||||
```yaml
|
{ .ConfigurationExample }
|
||||||
{ .GolangciYamlExample }
|
|
||||||
|
## Command-Line Options
|
||||||
|
|
||||||
|
```sh
|
||||||
|
golangci-lint run -h
|
||||||
|
{.RunHelpText}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When the `--cpu-profile-path` or `--mem-profile-path` arguments are specified, `golangci-lint` writes runtime profiling data
|
||||||
|
in the format expected by the [pprof](https://github.com/google/pprof) visualization tool.
|
||||||
|
|
||||||
|
When the `--trace-path` argument is specified, `golangci-lint` writes runtime tracing data in the format expected by
|
||||||
|
the `go tool trace` command and visualization tool.
|
||||||
|
|
||||||
## Cache
|
## Cache
|
||||||
|
|
||||||
GolangCI-Lint stores its cache in the [default user cache directory](https://golang.org/pkg/os/#UserCacheDir).
|
GolangCI-Lint stores its cache in the [default user cache directory](https://golang.org/pkg/os/#UserCacheDir).
|
||||||
|
@ -165,7 +165,7 @@ func buildTemplateContext() (map[string]string, error) {
|
|||||||
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
|
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lintersCfg, err := getLintersConfiguration(golangciYamlExample)
|
snippets, err := extractExampleSnippets(golangciYamlExample)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
|
return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err)
|
||||||
}
|
}
|
||||||
@ -202,8 +202,8 @@ func buildTemplateContext() (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"LintersExample": lintersCfg,
|
"LintersExample": snippets.LintersSettings,
|
||||||
"GolangciYamlExample": strings.TrimSpace(string(golangciYamlExample)),
|
"ConfigurationExample": snippets.ConfigurationFile,
|
||||||
"LintersCommandOutputEnabledOnly": string(lintersOutParts[0]),
|
"LintersCommandOutputEnabledOnly": string(lintersOutParts[0]),
|
||||||
"LintersCommandOutputDisabledOnly": string(lintersOutParts[1]),
|
"LintersCommandOutputDisabledOnly": string(lintersOutParts[1]),
|
||||||
"EnabledByDefaultLinters": getLintersListMarkdown(true),
|
"EnabledByDefaultLinters": getLintersListMarkdown(true),
|
||||||
@ -317,50 +317,137 @@ func getThanksList() string {
|
|||||||
return strings.Join(lines, "\n")
|
return strings.Join(lines, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLintersConfiguration(example []byte) (string, error) {
|
type SettingSnippets struct {
|
||||||
builder := &strings.Builder{}
|
ConfigurationFile string
|
||||||
|
LintersSettings string
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractExampleSnippets(example []byte) (*SettingSnippets, error) {
|
||||||
var data yaml.Node
|
var data yaml.Node
|
||||||
err := yaml.Unmarshal(example, &data)
|
err := yaml.Unmarshal(example, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
root := data.Content[0]
|
root := data.Content[0]
|
||||||
|
|
||||||
|
globalNode := &yaml.Node{
|
||||||
|
Kind: root.Kind,
|
||||||
|
Style: root.Style,
|
||||||
|
Tag: root.Tag,
|
||||||
|
Value: root.Value,
|
||||||
|
Anchor: root.Anchor,
|
||||||
|
Alias: root.Alias,
|
||||||
|
HeadComment: root.HeadComment,
|
||||||
|
LineComment: root.LineComment,
|
||||||
|
FootComment: root.FootComment,
|
||||||
|
Line: root.Line,
|
||||||
|
Column: root.Column,
|
||||||
|
}
|
||||||
|
|
||||||
|
snippets := SettingSnippets{}
|
||||||
|
|
||||||
|
builder := strings.Builder{}
|
||||||
|
|
||||||
for j, node := range root.Content {
|
for j, node := range root.Content {
|
||||||
if node.Value != "linters-settings" {
|
switch node.Value {
|
||||||
|
case "run", "output", "linters", "linters-settings", "issues", "severity":
|
||||||
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := root.Content[j+1]
|
nextNode := root.Content[j+1]
|
||||||
|
|
||||||
for i := 0; i < len(nodes.Content); i += 2 {
|
newNode := &yaml.Node{
|
||||||
r := &yaml.Node{
|
Kind: nextNode.Kind,
|
||||||
Kind: nodes.Kind,
|
|
||||||
Style: nodes.Style,
|
|
||||||
Tag: nodes.Tag,
|
|
||||||
Value: node.Value,
|
|
||||||
Content: []*yaml.Node{
|
Content: []*yaml.Node{
|
||||||
{
|
{
|
||||||
Kind: root.Content[j].Kind,
|
HeadComment: fmt.Sprintf("See the dedicated %q documentation section.", node.Value),
|
||||||
Value: root.Content[j].Value,
|
Kind: node.Kind,
|
||||||
|
Style: node.Style,
|
||||||
|
Tag: node.Tag,
|
||||||
|
Value: "option",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Kind: nodes.Kind,
|
Kind: node.Kind,
|
||||||
Content: []*yaml.Node{nodes.Content[i], nodes.Content[i+1]},
|
Style: node.Style,
|
||||||
|
Tag: node.Tag,
|
||||||
|
Value: "value",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(builder, "### %s\n\n", nodes.Content[i].Value)
|
globalNode.Content = append(globalNode.Content, node, newNode)
|
||||||
|
|
||||||
|
if node.Value == "linters-settings" {
|
||||||
|
snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = builder.WriteString(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"### `%s` configuration\n\nSee the dedicated [linters-settings](/usage/linters) documentation section.\n\n",
|
||||||
|
node.Value,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeSection := &yaml.Node{
|
||||||
|
Kind: root.Kind,
|
||||||
|
Style: root.Style,
|
||||||
|
Tag: root.Tag,
|
||||||
|
Value: root.Value,
|
||||||
|
Content: []*yaml.Node{node, nextNode},
|
||||||
|
}
|
||||||
|
|
||||||
|
snippet, errSnip := marshallSnippet(nodeSection)
|
||||||
|
if errSnip != nil {
|
||||||
|
return nil, errSnip
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = builder.WriteString(fmt.Sprintf("### `%s` configuration\n\n%s", node.Value, snippet))
|
||||||
|
}
|
||||||
|
|
||||||
|
overview, err := marshallSnippet(globalNode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
snippets.ConfigurationFile = overview + builder.String()
|
||||||
|
|
||||||
|
return &snippets, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLintersSettingSnippets(node, nextNode *yaml.Node) (string, error) {
|
||||||
|
builder := &strings.Builder{}
|
||||||
|
|
||||||
|
for i := 0; i < len(nextNode.Content); i += 2 {
|
||||||
|
r := &yaml.Node{
|
||||||
|
Kind: nextNode.Kind,
|
||||||
|
Style: nextNode.Style,
|
||||||
|
Tag: nextNode.Tag,
|
||||||
|
Value: node.Value,
|
||||||
|
Content: []*yaml.Node{
|
||||||
|
{
|
||||||
|
Kind: node.Kind,
|
||||||
|
Value: node.Value,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: nextNode.Kind,
|
||||||
|
Content: []*yaml.Node{nextNode.Content[i], nextNode.Content[i+1]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = fmt.Fprintf(builder, "### %s\n\n", nextNode.Content[i].Value)
|
||||||
_, _ = fmt.Fprintln(builder, "```yaml")
|
_, _ = fmt.Fprintln(builder, "```yaml")
|
||||||
|
|
||||||
const ident = 2
|
|
||||||
encoder := yaml.NewEncoder(builder)
|
encoder := yaml.NewEncoder(builder)
|
||||||
encoder.SetIndent(ident)
|
encoder.SetIndent(2)
|
||||||
|
|
||||||
err = encoder.Encode(r)
|
err := encoder.Encode(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -368,7 +455,28 @@ func getLintersConfiguration(example []byte) (string, error) {
|
|||||||
_, _ = fmt.Fprintln(builder, "```")
|
_, _ = fmt.Fprintln(builder, "```")
|
||||||
_, _ = fmt.Fprintln(builder)
|
_, _ = fmt.Fprintln(builder)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return builder.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func marshallSnippet(node *yaml.Node) (string, error) {
|
||||||
|
builder := &strings.Builder{}
|
||||||
|
|
||||||
|
if node.Value != "" {
|
||||||
|
_, _ = fmt.Fprintf(builder, "### %s\n\n", node.Value)
|
||||||
|
}
|
||||||
|
_, _ = fmt.Fprintln(builder, "```yaml")
|
||||||
|
|
||||||
|
encoder := yaml.NewEncoder(builder)
|
||||||
|
encoder.SetIndent(2)
|
||||||
|
|
||||||
|
err := encoder.Encode(node)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = fmt.Fprintln(builder, "```")
|
||||||
|
_, _ = fmt.Fprintln(builder)
|
||||||
|
|
||||||
return builder.String(), nil
|
return builder.String(), nil
|
||||||
}
|
}
|
||||||
|
20
scripts/expand_website_templates/main_test.go
Normal file
20
scripts/expand_website_templates/main_test.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_extractExampleSnippets(t *testing.T) {
|
||||||
|
t.Skip("only for debugging purpose")
|
||||||
|
|
||||||
|
example, err := os.ReadFile("../../../golangci-lint/.golangci.example.yml")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
m, err := extractExampleSnippets(example)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
t.Log(m)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user