Skip to content

Commit 73956a6

Browse files
authored
ci: add golangci linting + fixed deprecations (#212)
* ci: add `golangci` linting + fixed deprecations * adding a timeout * add verbose * add CRLF handling * test * crlf vs lf * added LF handling for windows * removed verbose on linter
1 parent 46b2d6f commit 73956a6

17 files changed

+146
-66
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@ jobs:
1313
- windows-latest
1414
- macos-latest
1515
steps:
16+
# Related issue: https://github.com/golangci/golangci-lint/issues/580
17+
- name: Windows - ensure LF line endings for gofmt
18+
if: matrix.os == 'windows-latest'
19+
run: |
20+
git config --global core.autocrlf false
21+
git config --global core.eol lf
22+
1623
- name: Check out code
1724
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
1825
- name: Setup Go
1926
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
2027
with:
2128
go-version-file: 'go.mod'
29+
- name: Run linters
30+
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
31+
with:
32+
version: latest
33+
args: --timeout=3m
2234
- name: go vet
2335
run: go vet ./...
2436
- name: Run tests

.golangci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
issues:
2+
max-per-linter: 0
3+
max-same-issues: 0
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- durationcheck
9+
- errcheck
10+
- exportloopref
11+
- forcetypeassert
12+
- gofmt
13+
- gosimple
14+
- ineffassign
15+
- makezero
16+
- misspell
17+
- nilerr
18+
- paralleltest
19+
- predeclared
20+
- staticcheck
21+
- tenv
22+
- unconvert
23+
- unparam
24+
- unused
25+
- vet

internal/cmd/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (cmd *generateCmd) Help() string {
4242
}
4343
})
4444

45-
strBuilder.WriteString(fmt.Sprintf("\nUsage: tfplugindocs generate [<args>]\n\n"))
45+
strBuilder.WriteString("\nUsage: tfplugindocs generate [<args>]\n\n")
4646
cmd.Flags().VisitAll(func(f *flag.Flag) {
4747
if f.DefValue != "" {
4848
strBuilder.WriteString(fmt.Sprintf(" --%s <ARG> %s%s%s (default: %q)\n",

internal/cmd/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (cmd *validateCmd) Help() string {
3030
}
3131
})
3232

33-
strBuilder.WriteString(fmt.Sprintf("\nUsage: tfplugindocs validate [<args>]\n\n"))
33+
strBuilder.WriteString("\nUsage: tfplugindocs validate [<args>]\n\n")
3434
cmd.Flags().VisitAll(func(f *flag.Flag) {
3535
if f.DefValue != "" {
3636
strBuilder.WriteString(fmt.Sprintf(" --%s <ARG> %s%s%s (default: %q)\n",

internal/mdplain/renderer.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,19 @@ func (options *Text) Emphasis(out *bytes.Buffer, text []byte) {
130130
out.Write(text)
131131
}
132132

133-
func (options *Text) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
134-
return
135-
}
133+
func (options *Text) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {}
136134

137-
func (options *Text) LineBreak(out *bytes.Buffer) {
138-
return
139-
}
135+
func (options *Text) LineBreak(out *bytes.Buffer) {}
140136

141137
func (options *Text) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) {
142138
out.Write(content)
143139
if !isRelativeLink(link) {
144140
out.WriteString(" ")
145141
out.Write(link)
146142
}
147-
return
148143
}
149144

150-
func (options *Text) RawHtmlTag(out *bytes.Buffer, text []byte) {
151-
return
152-
}
145+
func (options *Text) RawHtmlTag(out *bytes.Buffer, text []byte) {}
153146

154147
func (options *Text) TripleEmphasis(out *bytes.Buffer, text []byte) {
155148
out.Write(text)
@@ -159,9 +152,7 @@ func (options *Text) StrikeThrough(out *bytes.Buffer, text []byte) {
159152
out.Write(text)
160153
}
161154

162-
func (options *Text) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {
163-
return
164-
}
155+
func (options *Text) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {}
165156

166157
func (options *Text) Entity(out *bytes.Buffer, entity []byte) {
167158
out.Write(entity)
@@ -171,25 +162,15 @@ func (options *Text) NormalText(out *bytes.Buffer, text []byte) {
171162
out.Write(text)
172163
}
173164

174-
func (options *Text) Smartypants(out *bytes.Buffer, text []byte) {
175-
return
176-
}
165+
func (options *Text) Smartypants(out *bytes.Buffer, text []byte) {}
177166

178-
func (options *Text) DocumentHeader(out *bytes.Buffer) {
179-
return
180-
}
167+
func (options *Text) DocumentHeader(out *bytes.Buffer) {}
181168

182-
func (options *Text) DocumentFooter(out *bytes.Buffer) {
183-
return
184-
}
169+
func (options *Text) DocumentFooter(out *bytes.Buffer) {}
185170

186-
func (options *Text) TocHeader(text []byte, level int) {
187-
return
188-
}
171+
func (options *Text) TocHeader(text []byte, level int) {}
189172

190-
func (options *Text) TocFinalize() {
191-
return
192-
}
173+
func (options *Text) TocFinalize() {}
193174

194175
func doubleSpace(out *bytes.Buffer) {
195176
if out.Len() > 0 {

internal/provider/generate.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package provider
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"os/exec"
98
"path/filepath"
@@ -128,7 +127,7 @@ func (g *generator) Generate(ctx context.Context) error {
128127

129128
switch {
130129
case g.websiteTmpDir == "":
131-
g.websiteTmpDir, err = ioutil.TempDir("", "tfws")
130+
g.websiteTmpDir, err = os.MkdirTemp("", "tfws")
132131
if err != nil {
133132
return err
134133
}
@@ -249,7 +248,7 @@ func (g *generator) renderMissingResourceDoc(providerName, name, typeName string
249248
fallbackTmplPath = filepath.Join(g.websiteTmpDir, g.websiteSourceDir, fallbackTmplPath)
250249
if fileExists(fallbackTmplPath) {
251250
g.infof("resource %q fallback template exists", name)
252-
tmplData, err := ioutil.ReadFile(fallbackTmplPath)
251+
tmplData, err := os.ReadFile(fallbackTmplPath)
253252
if err != nil {
254253
return fmt.Errorf("unable to read file %q: %w", fallbackTmplPath, err)
255254
}
@@ -377,7 +376,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj
377376

378377
g.infof("rendering templated website to static markdown")
379378

380-
err = filepath.Walk(g.websiteTmpDir, func(path string, info os.FileInfo, err error) error {
379+
err = filepath.Walk(g.websiteTmpDir, func(path string, info os.FileInfo, _ error) error {
381380
if info.IsDir() {
382381
// skip directories
383382
return nil
@@ -410,7 +409,7 @@ func (g *generator) renderStaticWebsite(providerName string, providerSchema *tfj
410409

411410
renderedPath = strings.TrimSuffix(renderedPath, ext)
412411

413-
tmplData, err := ioutil.ReadFile(path)
412+
tmplData, err := os.ReadFile(path)
414413
if err != nil {
415414
return fmt.Errorf("unable to read file %q: %w", rel, err)
416415
}
@@ -492,7 +491,7 @@ func (g *generator) terraformProviderSchema(ctx context.Context, providerName st
492491

493492
shortName := providerShortName(providerName)
494493

495-
tmpDir, err := ioutil.TempDir("", "tfws")
494+
tmpDir, err := os.MkdirTemp("", "tfws")
496495
if err != nil {
497496
return nil, err
498497
}

internal/provider/template_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
func TestRenderStringTemplate(t *testing.T) {
10+
t.Parallel()
11+
1012
template := `
1113
Plainmarkdown: {{ plainmarkdown .Text }}
1214
Split: {{ $arr := split .Text " "}}{{ index $arr 3 }}

internal/provider/util.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package provider
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"log"
87
"os"
98
"os/exec"
@@ -78,7 +77,7 @@ func writeFile(path string, data string) error {
7877
return fmt.Errorf("unable to make dir %q: %w", dir, err)
7978
}
8079

81-
err = ioutil.WriteFile(path, []byte(data), 0644)
80+
err = os.WriteFile(path, []byte(data), 0644)
8281
if err != nil {
8382
return fmt.Errorf("unable to write file %q: %w", path, err)
8483
}
@@ -90,7 +89,7 @@ func runCmd(cmd *exec.Cmd) ([]byte, error) {
9089
output, err := cmd.CombinedOutput()
9190
if err != nil {
9291
log.Printf("error executing %q, %v", cmd.Path, cmd.Args)
93-
log.Printf(string(output))
92+
log.Print(string(output))
9493
return nil, fmt.Errorf("error executing %q: %w", cmd.Path, err)
9594
}
9695
return output, nil

internal/provider/util_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
)
99

1010
func Test_resourceSchema(t *testing.T) {
11+
t.Parallel()
12+
1113
cases := map[string]struct {
1214
schemas map[string]*tfjson.Schema
1315
providerShortName string
@@ -63,7 +65,11 @@ func Test_resourceSchema(t *testing.T) {
6365
}
6466

6567
for name, c := range cases {
68+
name := name
69+
c := c
6670
t.Run(name, func(t *testing.T) {
71+
t.Parallel()
72+
6773
actualSchema, actualResourceName := resourceSchema(c.schemas, c.providerShortName, c.templateFileName)
6874

6975
if !cmp.Equal(c.expectedSchema, actualSchema) {

internal/tmplfuncs/tmplfuncs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tmplfuncs
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87
"strings"
@@ -21,7 +20,7 @@ func CodeFile(format, file string) (string, error) {
2120
}
2221

2322
fullPath := filepath.Join(wd, file)
24-
content, err := ioutil.ReadFile(fullPath)
23+
content, err := os.ReadFile(fullPath)
2524
if err != nil {
2625
return "", fmt.Errorf("unable to read content from %q: %w", file, err)
2726
}

schemamd/behaviors_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
func TestChildAttributeIsRequired(t *testing.T) {
12+
t.Parallel()
13+
1214
for _, c := range []struct {
1315
name string
1416
att *tfjson.SchemaAttribute
@@ -33,7 +35,10 @@ func TestChildAttributeIsRequired(t *testing.T) {
3335
false,
3436
},
3537
} {
38+
c := c
3639
t.Run(c.name, func(t *testing.T) {
40+
t.Parallel()
41+
3742
actual := childAttributeIsRequired(c.att)
3843
if diff := cmp.Diff(c.expected, actual); diff != "" {
3944
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)
@@ -43,6 +48,8 @@ func TestChildAttributeIsRequired(t *testing.T) {
4348
}
4449

4550
func TestChildAttributeIsOptional(t *testing.T) {
51+
t.Parallel()
52+
4653
for _, c := range []struct {
4754
name string
4855
att *tfjson.SchemaAttribute
@@ -67,7 +74,10 @@ func TestChildAttributeIsOptional(t *testing.T) {
6774
true,
6875
},
6976
} {
77+
c := c
7078
t.Run(c.name, func(t *testing.T) {
79+
t.Parallel()
80+
7181
actual := childAttributeIsOptional(c.att)
7282
if diff := cmp.Diff(c.expected, actual); diff != "" {
7383
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)
@@ -77,6 +87,8 @@ func TestChildAttributeIsOptional(t *testing.T) {
7787
}
7888

7989
func TestChildAttributeIsReadOnly(t *testing.T) {
90+
t.Parallel()
91+
8092
for _, c := range []struct {
8193
name string
8294
att *tfjson.SchemaAttribute
@@ -119,7 +131,10 @@ func TestChildAttributeIsReadOnly(t *testing.T) {
119131
true,
120132
},
121133
} {
134+
c := c
122135
t.Run(c.name, func(t *testing.T) {
136+
t.Parallel()
137+
123138
actual := childAttributeIsReadOnly(c.att)
124139
if diff := cmp.Diff(c.expected, actual); diff != "" {
125140
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)
@@ -129,6 +144,8 @@ func TestChildAttributeIsReadOnly(t *testing.T) {
129144
}
130145

131146
func TestChildBlockIsRequired(t *testing.T) {
147+
t.Parallel()
148+
132149
for _, c := range []struct {
133150
name string
134151
block *tfjson.SchemaBlockType
@@ -170,7 +187,10 @@ func TestChildBlockIsRequired(t *testing.T) {
170187
false,
171188
},
172189
} {
190+
c := c
173191
t.Run(c.name, func(t *testing.T) {
192+
t.Parallel()
193+
174194
actual := childBlockIsRequired(c.block)
175195
if diff := cmp.Diff(c.expected, actual); diff != "" {
176196
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)
@@ -180,6 +200,8 @@ func TestChildBlockIsRequired(t *testing.T) {
180200
}
181201

182202
func TestChildBlockIsOptional(t *testing.T) {
203+
t.Parallel()
204+
183205
for _, c := range []struct {
184206
name string
185207
block *tfjson.SchemaBlockType
@@ -335,7 +357,10 @@ func TestChildBlockIsOptional(t *testing.T) {
335357
true,
336358
},
337359
} {
360+
c := c
338361
t.Run(c.name, func(t *testing.T) {
362+
t.Parallel()
363+
339364
actual := childBlockIsOptional(c.block)
340365
if diff := cmp.Diff(c.expected, actual); diff != "" {
341366
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)
@@ -345,6 +370,8 @@ func TestChildBlockIsOptional(t *testing.T) {
345370
}
346371

347372
func TestChildBlockIsReadOnly(t *testing.T) {
373+
t.Parallel()
374+
348375
for _, c := range []struct {
349376
name string
350377
block *tfjson.SchemaBlockType
@@ -490,7 +517,10 @@ func TestChildBlockIsReadOnly(t *testing.T) {
490517
true,
491518
},
492519
} {
520+
c := c
493521
t.Run(c.name, func(t *testing.T) {
522+
t.Parallel()
523+
494524
actual := childBlockIsReadOnly(c.block)
495525
if diff := cmp.Diff(c.expected, actual); diff != "" {
496526
t.Fatalf("Unexpected diff (-wanted, +got): %s", diff)

0 commit comments

Comments
 (0)