docs: improve plugins page (#4494)

This commit is contained in:
Ludovic Fernandez 2024-03-13 13:48:59 +01:00 committed by GitHub
parent 2a1afc14cb
commit eaf3ff0741
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 7 deletions

View File

@ -49,7 +49,7 @@
- label: Plugins
items:
- label: Module Plugin System
link: /contributing/new-linters/
link: /plugins/module-plugins/
- label: Go Plugin System
link: /contributing/private-linters/
link: /plugins/go-plugins/

View File

@ -69,3 +69,11 @@ linters:
enable:
- foo
```
## Reference
The configuration file can be validated with the JSON Schema: https://golangci-lint.run/jsonschema/custom-gcl.jsonschema.json
```yml
{ .CustomGCLReference }
```

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
"reflect"
"sort"
@ -17,6 +18,20 @@ import (
const listItemPrefix = "list-item-"
func getExampleSnippets() (*SettingSnippets, error) {
reference, err := os.ReadFile(".golangci.reference.yml")
if err != nil {
return nil, fmt.Errorf("can't read .golangci.reference.yml: %w", err)
}
snippets, err := extractExampleSnippets(reference)
if err != nil {
return nil, fmt.Errorf("can't extract example snippets from .golangci.reference.yml: %w", err)
}
return snippets, nil
}
func getLintersListMarkdown(enabled bool) string {
linters, err := readJSONFile[[]*types.LinterWrapper](filepath.Join("assets", "linters-info.json"))
if err != nil {

View File

@ -119,14 +119,14 @@ func getLatestVersion() (string, error) {
}
func buildTemplateContext() (map[string]string, error) {
golangciYamlExample, err := os.ReadFile(".golangci.reference.yml")
snippets, err := getExampleSnippets()
if err != nil {
return nil, fmt.Errorf("can't read .golangci.reference.yml: %w", err)
return nil, err
}
snippets, err := extractExampleSnippets(golangciYamlExample)
pluginReference, err := getPluginReference()
if err != nil {
return nil, fmt.Errorf("can't read .golangci.reference.yml: %w", err)
return nil, fmt.Errorf("failed to read plugin reference file: %w", err)
}
helps, err := readJSONFile[types.CLIHelp](filepath.Join("assets", "cli-help.json"))
@ -150,7 +150,7 @@ func buildTemplateContext() (map[string]string, error) {
}
return map[string]string{
"LintersExample": snippets.LintersSettings,
"CustomGCLReference": pluginReference,
"ConfigurationExample": snippets.ConfigurationFile,
"LintersCommandOutputEnabledOnly": helps.Enable,
"LintersCommandOutputDisabledOnly": helps.Disable,

View File

@ -0,0 +1,15 @@
package main
import (
"fmt"
"os"
)
func getPluginReference() (string, error) {
reference, err := os.ReadFile(".custom-gcl.reference.yml")
if err != nil {
return "", fmt.Errorf("can't read .custom-gcl.reference.yml: %w", err)
}
return string(reference), nil
}