Skip to content

Commit 1c91afb

Browse files
authored
chore: add website (#6)
1 parent e6dabd8 commit 1c91afb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+13332
-104
lines changed

.codespellrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[codespell]
22
# Comma separated list of words to be ignored. Words must be lowercased.
33
ignore-words-list = decorder
4+
skip = **/package-lock.json,**/pnpm-lock.yaml,**/node_modules/**,./web/playground/dist/*

.github/dependabot.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
2-
32
version: 2
43
updates:
5-
- package-ecosystem: "gomod" # See documentation for possible values
6-
directory: "/" # Location of package manifests
4+
- package-ecosystem: "gomod"
5+
directory: "/"
76
schedule:
87
interval: "weekly"
98
groups:
@@ -21,3 +20,15 @@ updates:
2120
commit-message:
2221
prefix: "chore"
2322
include: "scope"
23+
- package-ecosystem: "npm"
24+
directory: "web/playground"
25+
schedule:
26+
interval: "weekly"
27+
groups:
28+
all-deps:
29+
applies-to: version-updates
30+
patterns:
31+
- "*"
32+
commit-message:
33+
prefix: "chore"
34+
include: "scope"

.github/workflows/pages.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: pages.yml
2+
3+
permissions:
4+
contents: read
5+
pages: write
6+
id-token: write
7+
8+
on:
9+
workflow_dispatch:
10+
push:
11+
12+
concurrency:
13+
group: 'pages'
14+
cancel-in-progress: true
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: checkout
21+
uses: actions/checkout@v4
22+
- name: setup Node
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 23
26+
cache: 'npm'
27+
cache-dependency-path: web/playground/package-lock.json
28+
- name: install dependencies
29+
run: npm install ./web/playground
30+
- name: build
31+
run: npm run build --prefix ./web/playground
32+
- name: setup Pages
33+
uses: actions/configure-pages@v4
34+
- name: upload artifact
35+
uses: actions/upload-pages-artifact@v3
36+
with:
37+
path: './web/playground/dist'
38+
- name: deploy to GitHub Pages
39+
id: deployment
40+
uses: actions/deploy-pages@v4

.markdownlint-cli2.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"gitignore": true,
66
// Define glob expressions to ignore
77
"ignores": [
8-
"LICENSE.md"
8+
"LICENSE.md",
9+
"*/node_modules/*.md"
910
],
1011
"config": {
1112
// MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md

internal/cmd/lint.go renamed to commands/lint.go

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
package cmd
1+
package commands
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
67
"runtime/debug"
78

89
"github.com/fatih/color"
910
"github.com/spf13/cobra"
1011

11-
"github.com/manuelarte/golangci-lint-linter/internal"
12-
"github.com/manuelarte/golangci-lint-linter/internal/linters"
12+
"github.com/manuelarte/golangci-lint-linter/linters"
13+
"github.com/manuelarte/golangci-lint-linter/models"
1314
)
1415

1516
//nolint:gochecknoglobals // color red
@@ -30,29 +31,13 @@ func RegisterLintCommand() *cobra.Command {
3031
return rootCMD
3132
}
3233

33-
//nolint:gocognit // TODO: refactor later
34-
func run(cmd *cobra.Command, args []string) {
35-
path := args[0]
36-
37-
isFix, err := cmd.Flags().GetBool("fix")
34+
func Lint(input []byte, isFix bool) (models.Golangci, []models.Report, error) {
35+
golangci, err := models.Parse(input)
3836
if err != nil {
39-
errorMsg := errorColor.Sprintf("Error reading flag fix: %s\n", err)
40-
cmd.PrintErrln(errorMsg)
41-
42-
return
43-
}
44-
45-
golangci, err := readYamlFile(path)
46-
if err != nil {
47-
errorMsg := errorColor.Sprintf("Error reading yaml file: %s\n", err)
48-
cmd.PrintErrf(errorMsg)
49-
50-
return
37+
return nil, nil, fmt.Errorf("error reading yaml file: %w", err)
5138
}
5239

53-
cmd.Printf("Linting: %q\n", path)
54-
55-
allReports := make([]internal.Report, 0)
40+
allReports := make([]models.Report, 0)
5641

5742
for _, linter := range getAllLinters() {
5843
linterReports := linter.Lint(golangci)
@@ -61,51 +46,71 @@ func run(cmd *cobra.Command, args []string) {
6146
if fixer, ok := linter.(linters.Fixer); ok {
6247
errFix := fixer.Fix(golangci)
6348
if errFix != nil {
64-
errorMsg := errorColor.Sprintf("Error applying fix: %s", errFix)
65-
cmd.PrintErrf("%s\n", errorMsg)
66-
os.Exit(1)
49+
return nil, nil, fmt.Errorf("error applying fix: %w", errFix)
6750
}
6851
}
6952
} else {
7053
allReports = append(allReports, linterReports...)
7154
}
7255
}
7356

74-
cmd.Printf("Found: %d issue(s)\n", len(allReports))
57+
return golangci, allReports, nil
58+
}
7559

76-
for _, report := range allReports {
77-
errorMsg := errorColor.Sprintf("%s", report)
78-
cmd.PrintErrf("%s\n", errorMsg)
60+
func run(cmd *cobra.Command, args []string) {
61+
path := args[0]
62+
63+
isFix, err := cmd.Flags().GetBool("fix")
64+
if err != nil {
65+
errorMsg := errorColor.Sprintf("Error reading flag fix: %s\n", err)
66+
cmd.PrintErrln(errorMsg)
67+
68+
return
7969
}
8070

71+
input, errReadingFile := os.ReadFile(filepath.Clean(path))
72+
if errReadingFile != nil {
73+
errorMsg := errorColor.Sprintf("Error reading file: %s\n", errReadingFile)
74+
cmd.PrintErrf(errorMsg)
75+
76+
return
77+
}
78+
79+
cmd.Printf("Linting: %q\n", path)
80+
81+
golangciFixed, reports, err := Lint(input, isFix)
82+
if err != nil {
83+
errorMsg := errorColor.Sprintf("Error Linting %s: %s\n", path, err)
84+
cmd.PrintErrf(errorMsg)
85+
os.Exit(1)
86+
}
87+
88+
cmd.Printf("Found: %d issue(s)\n", len(reports))
89+
8190
if isFix {
82-
fixedFile, errM := golangci.Marshal()
91+
fixedBytes, errM := golangciFixed.Marshal()
8392
if errM != nil {
8493
errorMsg := errorColor.Sprintf("Error Marshaling file: %s\n", errM)
8594
cmd.PrintErrf(errorMsg)
8695
os.Exit(1)
8796
}
8897

89-
err = os.WriteFile(path, fixedFile, 0o600)
98+
err = os.WriteFile(path, fixedBytes, 0o600)
9099
if err != nil {
91100
errorMsg := errorColor.Sprintf("Error writing file: %s\n", err)
92101
cmd.PrintErrf(errorMsg)
93102
os.Exit(1)
94103
}
95104
}
96105

97-
if len(allReports) > 0 {
98-
os.Exit(1)
106+
for _, report := range reports {
107+
errorMsg := errorColor.Sprintf("%s", report)
108+
cmd.PrintErrf("%s\n", errorMsg)
99109
}
100-
}
101110

102-
func readYamlFile(path string) (internal.Golangci, error) {
103-
input, errReadingFile := os.ReadFile(filepath.Clean(path))
104-
if errReadingFile != nil {
105-
return internal.YamlGolangci{}, errReadingFile
111+
if len(reports) > 0 {
112+
os.Exit(1)
106113
}
107-
108-
return internal.Parse(input)
109114
}
110115

111116
func getAllLinters() []linters.Linter {

internal/linters/model.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

internal/linters/disabled_linters_with_reason.go renamed to linters/disabled_linters_with_reason.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ package linters
33
import (
44
"fmt"
55

6-
"github.com/manuelarte/golangci-lint-linter/internal"
6+
"github.com/manuelarte/golangci-lint-linter/models"
77
)
88

99
var _ Linter = new(DisabledLintersWithReason)
1010

1111
type DisabledLintersWithReason struct {
12-
rule internal.RuleCode
12+
rule models.RuleCode
1313
}
1414

1515
func NewDisabledLintersWithReason() *DisabledLintersWithReason {
1616
return &DisabledLintersWithReason{
17-
rule: internal.GC021,
17+
rule: models.GC021,
1818
}
1919
}
2020

21-
func (l DisabledLintersWithReason) Lint(golangci internal.Golangci) []internal.Report {
22-
reports := make([]internal.Report, 0)
21+
func (l DisabledLintersWithReason) Rule() models.RuleCode {
22+
return l.rule
23+
}
24+
25+
func (l DisabledLintersWithReason) Lint(golangci models.Golangci) []models.Report {
26+
reports := make([]models.Report, 0)
2327

2428
linters, ok := golangci.GetLinters()
2529
if !ok {
@@ -34,7 +38,7 @@ func (l DisabledLintersWithReason) Lint(golangci internal.Golangci) []internal.R
3438
for i, disable := range disabled {
3539
_, hasComment := golangci.GetComment(fmt.Sprintf("$.linters.disable[%d]", i))
3640
if !hasComment {
37-
reports = append(reports, internal.Report{
41+
reports = append(reports, models.Report{
3842
Rule: l.rule,
3943
Message: fmt.Sprintf("linters.disable.%s does not have a reason", disable),
4044
})

internal/linters/disabled_linters_with_reason_test.go renamed to linters/disabled_linters_with_reason_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package linters
33
import (
44
"testing"
55

6-
"github.com/manuelarte/golangci-lint-linter/internal"
6+
"github.com/manuelarte/golangci-lint-linter/models"
77
)
88

99
func TestDisabledLintersWithReason_Lint(t *testing.T) {
@@ -51,7 +51,7 @@ linters:
5151

5252
for name, test := range testCases {
5353
t.Run(name, func(t *testing.T) {
54-
golangci, err := internal.Parse(test.input)
54+
golangci, err := models.Parse(test.input)
5555
if err != nil {
5656
t.Fatal(err)
5757
}

internal/linters/linter_fields_sorted.go renamed to linters/linter_fields_sorted.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ import (
55
"slices"
66

77
"github.com/manuelarte/golangci-lint-linter/internal"
8+
"github.com/manuelarte/golangci-lint-linter/models"
89
)
910

1011
var _ Linter = new(LinterFieldsSorted)
1112

1213
type LinterFieldsSorted struct {
13-
rule internal.RuleCode
14+
rule models.RuleCode
1415
expectedOrder map[string]int
1516
}
1617

1718
func NewLinterFieldsSorted() *LinterFieldsSorted {
1819
expectedOrder := map[string]int{"default": 0, "enable": 1, "disable": 2, "settings": 3, "exclusions": 4}
1920

2021
return &LinterFieldsSorted{
21-
rule: internal.GC013,
22+
rule: models.GC013,
2223
expectedOrder: expectedOrder,
2324
}
2425
}
2526

26-
func (l LinterFieldsSorted) Lint(golangci internal.Golangci) []internal.Report {
27-
reports := make([]internal.Report, 0)
27+
func (l LinterFieldsSorted) Rule() models.RuleCode {
28+
return l.rule
29+
}
30+
31+
func (l LinterFieldsSorted) Lint(golangci models.Golangci) []models.Report {
32+
reports := make([]models.Report, 0)
2833

2934
linters, ok := golangci.GetLinters()
3035
if !ok {
@@ -45,7 +50,7 @@ func (l LinterFieldsSorted) Lint(golangci internal.Golangci) []internal.Report {
4550
})
4651

4752
if !internal.EqualArray(fields, sorted) {
48-
reports = append(reports, internal.Report{
53+
reports = append(reports, models.Report{
4954
Rule: l.rule,
5055
Message: "linters fields are not sorted",
5156
})
@@ -54,7 +59,7 @@ func (l LinterFieldsSorted) Lint(golangci internal.Golangci) []internal.Report {
5459
return reports
5560
}
5661

57-
func (l LinterFieldsSorted) Fix(golangci internal.Golangci) error {
62+
func (l LinterFieldsSorted) Fix(golangci models.Golangci) error {
5863
linters, ok := golangci.GetLinters()
5964
if !ok {
6065
return nil

0 commit comments

Comments
 (0)