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 - label: Plugins
items: items:
- label: Module Plugin System - label: Module Plugin System
link: /contributing/new-linters/ link: /plugins/module-plugins/
- label: Go Plugin System - label: Go Plugin System
link: /contributing/private-linters/ link: /plugins/go-plugins/

View File

@ -69,3 +69,11 @@ linters:
enable: enable:
- foo - 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 ( import (
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"sort" "sort"
@ -17,6 +18,20 @@ import (
const listItemPrefix = "list-item-" 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 { func getLintersListMarkdown(enabled bool) string {
linters, err := readJSONFile[[]*types.LinterWrapper](filepath.Join("assets", "linters-info.json")) linters, err := readJSONFile[[]*types.LinterWrapper](filepath.Join("assets", "linters-info.json"))
if err != nil { if err != nil {

View File

@ -119,14 +119,14 @@ func getLatestVersion() (string, error) {
} }
func buildTemplateContext() (map[string]string, error) { func buildTemplateContext() (map[string]string, error) {
golangciYamlExample, err := os.ReadFile(".golangci.reference.yml") snippets, err := getExampleSnippets()
if err != nil { 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 { 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")) 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{ return map[string]string{
"LintersExample": snippets.LintersSettings, "CustomGCLReference": pluginReference,
"ConfigurationExample": snippets.ConfigurationFile, "ConfigurationExample": snippets.ConfigurationFile,
"LintersCommandOutputEnabledOnly": helps.Enable, "LintersCommandOutputEnabledOnly": helps.Enable,
"LintersCommandOutputDisabledOnly": helps.Disable, "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
}