8000 feat(chore): add golangci-lint · symfony-cli/symfony-cli@1ffee82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ffee82

Browse files
committed
feat(chore): add golangci-lint
1 parent c13edab commit 1ffee82

Some content is hidden

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

78 files changed

+720
-668
lines changed

.github/workflows/releaser.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ jobs:
6464
echo '"go generate" changed some Go generated code, run "symfony cloud:self-update" then "go generate ./" locally and make a Pull Request with the changes'
6565
git diff
6666
exit 1
67+
-
68+
name: Run golangci-lint
69+
uses: golangci/golangci-lint-action@v3
70+
with:
71+
only-new-issues: true
6772
-
6873
name: Test
6974
run: go test -v ./...

.golangci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
run:
2+
timeout: 30s
3+
issues-exit-code: 1
4+
5+
linters:
6+
enable:
7+
- gci
8+
- wrapcheck
9+
10+
linters-settings:
11+
wrapcheck:
12+
ignorePackageGlobs:
13+
# We already make sure your own packages wrap errors properly
14+
- github.com/symfony-cli/*
15+
errcheck:
16+
ignore: github.com/symfony-cli/terminal:^(Ep|P)rint

book/checkout.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
func (b *Book) Checkout(step string) error {
3636
// FIXME: keep vendor/ node_modules/ around before git clean, but them back as they will be updated the right way, less Internet traffic
3737
// FIXME: if the checkout is to a later step, no need to remove the DB, we can just migrate it
38-
os.Chdir(b.Dir)
38+
_ = os.Chdir(b.Dir)
3939
step = strings.Replace(step, ".", "-", -1)
4040
tag := fmt.Sprintf("step-%s", step)
4141
branch := "work-" + tag
@@ -80,21 +80,21 @@ func (b *Book) Checkout(step string) error {
8080

8181
printBanner("<comment>[GIT]</> Removing Git ignored files (vendor, cache, ...)", b.Debug)
8282
if err := executeCommand([]string{"git", "clean", "-d", "-f", "-x"}, b.Debug, false, nil); err != nil {
83-
return err
83+
return errors.WithStack(err)
8484
}
8585
printBanner("<comment>[GIT]</> Resetting Git staged files", b.Debug)
8686
if err := executeCommand([]string{"git", "reset", "HEAD", "."}, b.Debug, false, nil); err != nil {
87-
return err
87+
return errors.WithStack(err)
8888
}
8989
printBanner("<comment>[GIT]</> Removing un-tracked Git files", b.Debug)
9090
if err := executeCommand([]string{"git", "checkout", "."}, b.Debug, false, nil); err != nil {
91-
return err
91+
return errors.WithStack(err)
9292
}
9393

9494
printBanner("<comment>[WEB]</> Adding .env.local", b.Debug)
9595
emptyFile, err := os.Create(filepath.Join(b.Dir, ".env.local"))
9696
if err != nil {
97-
return err
97+
return errors.WithStack(err)
9898
}
9999
emptyFile.Close()
100100
if !b.Debug {
@@ -110,40 +110,44 @@ func (b *Book) Checkout(step string) error {
110110
printBanner("<comment>[WEB]</> Stopping Docker Containers", b.Debug)
111111
if hasDocker {
112112
if err := executeCommand(append(dockerComposeBin(), "down", "--remove-orphans"), b.Debug, false, nil); err != nil {
113-
return err
113+
return errors.WithStack(err)
114114
}
115115
} else {
116116
terminal.Println("Skipped for this step")
117117
}
118118

119119
printBanner("<comment>[WEB]</> Stopping the Local Web Server", b.Debug)
120-
executeCommand([]string{"symfony", "server:stop"}, b.Debug, true, nil)
120+
if err := executeCommand([]string{"symfony", "server:stop"}, b.Debug, true, nil); err != nil {
121+
return errors.Wrap(err, "cannot stop the symfony server")
122+
}
121123

122124
printBanner("<comment>[WEB]</> Stopping the Platform.sh tunnel", b.Debug)
123125
if err := executeCommand([]string{"symfony", "tunnel:close", "-y"}, b.Debug, true, nil); err != nil {
124-
return err
126+
return errors.WithStack(err)
125127
}
126128

127129
printBanner("<comment>[GIT]</> Checking out the step", b.Debug)
128130
if err := executeCommand([]string{"git", "checkout", "-B", branch, tag}, b.Debug, false, nil); err != nil {
129-
return err
131+
return errors.WithStack(err)
130132
}
131133

132134
printBanner("<comment>[SPA]</> Stopping the Local Web Server", b.Debug)
133135
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil {
134-
executeCommand([]string{"symfony", "server:stop", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, true, nil)
136+
if err := executeCommand([]string{"symfony", "server:stop", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, true, nil); err != nil {
137+
return errors.Wrap(err, "cannot stop the symfony server")
138+
}
135139
} else {
136140
terminal.Println("Skipped for this step")
137141
}
138142

139143
printBanner("<comment>[WEB]</> Installing Composer dependencies (might take some time)", b.Debug)
140144
if err := executeCommand([]string{"symfony", "composer", "install"}, b.Debug, false, nil); err != nil {
141-
return err
145+
return errors.WithStack(err)
142146
}
143147

144148
printBanner("<comment>[WEB]</> Adding .env.local", b.Debug)
145149
if emptyFile, err = os.Create(filepath.Join(b.Dir, ".env.local")); err != nil {
146-
return err
150+
return errors.WithStack(err)
147151
}
148152
emptyFile.Close()
149153
if !b.Debug {
@@ -153,7 +157,7 @@ func (b *Book) Checkout(step string) error {
153157
printBanner("<comment>[WEB]</> Starting Docker Compose", b.Debug)
154158
if hasDocker {
155159
if err := executeCommand(append(dockerComposeBin(), "up", "-d"), b.Debug, false, nil); err != nil {
156-
return err
160+
return errors.WithStack(err)
157161
}
158162
printBanner("<comment>[WEB]</> Waiting for the Containers to be ready", b.Debug)
159163
if _, err := os.Stat(filepath.Join(b.Dir, "src", "MessageHandler", "CommentMessageHandler.php")); err == nil {
@@ -179,7 +183,7 @@ func (b *Book) Checkout(step string) error {
179183
}
180184
if hasMigrations {
181185
if err := executeCommand([]string{"symfony", "console", "doctrine:migrations:migrate", "-n"}, b.Debug, false, nil); err != nil {
182-
return err
186+
return errors.WithStack(err)
183187
}
184188
} else {
185189
terminal.Println("Skipped for this step")
@@ -188,7 +192,7 @@ func (b *Book) Checkout(step string) error {
188192
printBanner("<comment>[WEB]</> Inserting Fixtures", b.Debug)
189193
if _, err := os.Stat(filepath.Join(b.Dir, "src", "DataFixtures")); err == nil {
190194
if err := executeCommand([]string{"symfony", "console", "doctrine:fixtures:load", "-n"}, b.Debug, false, nil); err != nil {
191-
return err
195+
return errors.WithStack(err)
192196
}
193197
} else {
194198
terminal.Println("Skipped for this step")
@@ -202,7 +206,7 @@ func (b *Book) Checkout(step string) error {
202206
args = []string{"yarn", "install"}
203207
}
204208
if err := executeCommand(args, b.Debug, false, nil); err != nil {
205-
return err
209+
return errors.WithStack(err)
206210
}
207211
} else {
208212
terminal.Println("Skipped for this step")
@@ -215,38 +219,38 @@ func (b *Book) Checkout(step string) error {
215219
args = []string{"yarn", "encore", "dev"}
216220
}
217221
if err := executeCommand(args, b.Debug, false, nil); err != nil {
218-
return err
222+
return errors.WithStack(err)
219223
}
220224
} else {
221225
terminal.Println("Skipped for this step")
222226
}
223227

224228
printBanner("<comment>[WEB]</> Starting the Local Web Server", b.Debug)
225229
if err := executeCommand([]string{"symfony", "server:start", "-d"}, b.Debug, false, nil); err != nil {
226-
return err
230+
return errors.WithStack(err)
227231
}
228232

229233
printBanner("<comment>[WEB]</> Starting Message Consumer", b.Debug)
230234
if _, err := os.Stat(filepath.Join(b.Dir, "src", "MessageHandler", "CommentMessageHandler.php")); err == nil {
231235
if err := executeCommand([]string{"symfony", "run", "-d", "--watch", "config,src,templates,vendor", "symfony", "console", "messenger:consume", "async", "-vv"}, b.Debug, false, nil); err != nil {
232-
return err
236+
return errors.WithStack(err)
233237
}
234238
} else {
235239
terminal.Println("Skipped for this step")
236240
}
237241

238242
printBanner("<comment>[SPA]</> Installing Node dependencies (might take some time)", b.Debug)
239243
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil {
240-
os.Chdir(filepath.Join(b.Dir, "spa"))
244+
_ = os.Chdir(filepath.Join(b.Dir, "spa"))
241245
args := []string{"npm", "install"}
242246
if _, err := os.Stat(filepath.Join(b.Dir, "yarn.lock")); err == nil {
243247
// old version of the book using Yarn instead of npm
244248
args = []string{"yarn", "install"}
245249
}
246250
if err := executeCommand(args, b.Debug, false, nil); err != nil {
247-
return err
251+
return errors.WithStack(err)
248252
}
249-
os.Chdir(b.Dir)
253+
_ = os.Chdir(b.Dir)
250254
} else {
251255
terminal.Println("Skipped for this step")
252256
}
@@ -264,24 +268,24 @@ func (b *Book) Checkout(step string) error {
264268
if endpoint.String() == "" {
265269
return errors.Errorf("unable to get the URL of the local web server:\n%s\n%s", stderr.String(), endpoint.String())
266270
}
267-
os.Chdir(filepath.Join(b.Dir, "spa"))
271+
_ = os.Chdir(filepath.Join(b.Dir, "spa"))
268272
env := append(os.Environ(), "API_ENDPOINT="+endpoint.String())
269273
args := []string{"npx", "encore", "dev"}
270274
if _, err := os.Stat(filepath.Join(b.Dir, "yarn.lock")); err == nil {
271275
args = []string{"yarn", "encore", "dev"}
272276
}
273277
if err := executeCommand(args, b.Debug, false, env); err != nil {
274-
return err
278+
return errors.WithStack(err)
275279
}
276-
os.Chdir(b.Dir)
280+
_ = os.Chdir(b.Dir)
277281
} else {
278282
terminal.Println("Skipped for this step")
279283
}
280284

281285
printBanner("<comment>[SPA]</> Starting the Local Web Server", b.Debug)
282286
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil {
283287
if err := executeCommand([]string{"symfony", "server:start", "-d", "--passthru", "index.html", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, false, nil); err != nil {
284-
return err
288+
return errors.WithStack(err)
285289
}
286290
} else {
287291
terminal.Println("Skipped for this step")
@@ -322,7 +326,7 @@ func executeCommand(args []string, debug, skipErrors bool, env []string) error {
322326
terminal.Println("<error>[ KO ]</>")
323327
}
324328
terminal.Print(buf.String())
325-
return err
329+
return errors.WithStack(err)
326330
}
327331
if !debug {
328332
terminal.Println("<info>[ OK ]</>")

book/clone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (b *Book) Clone(version string) error {
3333
ui.Section("Checking Book Requirements")
3434
ready, err := CheckRequirements()
3535
if err != nil {
36-
return err
36+
return errors.WithStack(err)
3737
}
3838
terminal.Println("")
3939
if !ready {
@@ -50,7 +50,7 @@ func (b *Book) Clone(version string) error {
5050
}
5151
terminal.Println("")
5252

53-
os.Chdir(b.Dir)
53+
_ = os.Chdir(b.Dir)
5454
// checkout the first step by default
5555
ui.Section("Getting Ready for the First Step of the Book")
5656
if err := b.Checkout("3"); err != nil {
@@ -59,7 +59,7 @@ func (b *Book) Clone(version string) error {
5959
terminal.Println("Re-run the command with <comment>--debug</> to get more information about the error")
6060
terminal.Println("")
6161
}
62-
return err
62+
return errors.WithStack(err)
6363
}
6464
return nil
6565
}

book/reqs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ func CheckRequirements() (bool, error) {
6565
// PHP
6666
minv, err := version.NewVersion("8.1.0")
6767
if err != nil {
68-
return false, err
68+
return false, errors.WithStack(err)
6969
}
7070
store := phpstore.New(util.GetHomeDir(), true, nil)
7171
wd, err := os.Getwd()
7272
if err != nil {
73 10000 -
return false, err
73+
return false, errors.WithStack(err)
7474
}
7575
v, _, _, _ := store.BestVersionForDir(wd)
7676
if v == nil {

commands/book_check_reqs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package commands
2121

2222
import (
23+
"github.com/pkg/errors"
2324
"github.com/symfony-cli/console"
2425
"github.com/symfony-cli/symfony-cli/book"
2526
"github.com/symfony-cli/terminal"
@@ -35,7 +36,7 @@ var bookCheckReqsCmd = &console.Command{
3536

3637
ready, err := book.CheckRequirements()
3738
if err != nil {
38-
return err
39+
return errors.WithStack(err)
3940
}
4041
terminal.Println("")
4142
if ready {

commands/book_checkout.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package commands
2121

2222
import (
23+
"github.com/pkg/errors"
2324
"github.com/symfony-cli/console"
2425
"github.com/symfony-cli/symfony-cli/book"
2526
"github.com/symfony-cli/terminal"
@@ -40,7 +41,7 @@ var bookCheckoutCmd = &console.Command{
4041
Action: func(c *console.Context) error {
4142
dir, err := getProjectDir(c.String("dir"))
4243
if err != nil {
43-
return err
44+
return errors.WithStack(err)
4445
}
4546

4647
book := &book.Book{
@@ -50,7 +51,7 @@ var bookCheckoutCmd = &console.Command{
5051
}
5152
if !c.Bool("force") {
5253
if err := book.CheckRepository(); err != nil {
53-
return err
54+
return errors.WithStack(err)
5455
}
5556
}
5657
if err := book.Checkout(c.Args().Get("step")); err != nil {
@@ -59,7 +60,7 @@ var bookCheckoutCmd = &console.Command{
5960
terminal.Println("Re-run the command with <comment>--debug</> to get more information about the error")
6061
terminal.Println("")
6162
}
62-
return err
63+
return errors.WithStack(err)
6364
}
6465
return nil
6566
},

commands/init_templating.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package commands
2222
import (
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"net/http"
2726
"net/url"
2827
"os"
@@ -194,19 +193,19 @@ func getTemplates(rootDirectory, chosenTemplateName string, minorPHPVersion stri
194193
)
195194

196195
if isFile {
197-
templateConfigBytes, err = ioutil.ReadFile(chosenTemplateName)
196+
templateConfigBytes, err = os.ReadFile(chosenTemplateName)
198197
} else {
199198
var resp *http.Response
200199
resp, err = http.Get(chosenTemplateName)
201200
if err != nil {
202-
return nil, err
201+
return nil, errors.WithStack(err)
203202
}
204203
if resp.StatusCode >= 400 {
205204
return nil, errors.Errorf("Got HTTP status code >= 400: %s", resp.Status)
206205
}
207206
defer resp.Body.Close()
208207

209-
templateConfigBytes, err = ioutil.ReadAll(resp.Body)
208+
templateConfigBytes, err = io.ReadAll(resp.Body)
210209
}
211210

212211
if err != nil {
@@ -219,7 +218,7 @@ func getTemplates(rootDirectory, chosenTemplateName string, minorPHPVersion stri
219218

220219
terminal.Logger.Info().Msg("Using template " + chosenTemplateName)
221220
} else {
222-
files, err := ioutil.ReadDir(directory)
221+
files, err := os.ReadDir(directory)
223222
if err != nil {
224223
return nil, errors.Wrap(err, "could not read configuration templates")
225224
}
@@ -240,7 +239,7 @@ func getTemplates(rootDirectory, chosenTemplateName string, minorPHPVersion stri
240239
continue
241240
}
242241

243-
templateConfigBytes, err := ioutil.ReadFile(filepath.Join(directory, file.Name()))
242+
templateConfigBytes, err := os.ReadFile(filepath.Join(directory, file.Name()))
244243
if err != nil {
245244
if isTemplateChosen {
246245
return nil, errors.Wrap(err, "could not apply configuration template")
@@ -275,7 +274,7 @@ func getTemplates(rootDirectory, chosenTemplateName string, minorPHPVersion stri
275274
return nil, errors.New("no matching template found")
276275
}
277276

278-
phpini, err := ioutil.ReadFile(filepath.Join(directory, "php.ini"))
277+
phpini, err := os.ReadFile(filepath.Join(directory, "php.ini"))
279278
if err != nil {
280279
return nil, errors.New("unable to find the php.ini template")
281280
}

0 commit comments

Comments
 (0)
0