Skip to content

Commit 13daa6d

Browse files
committed
feat: formatting with golangci-lint and gci
1 parent 20c1ffe commit 13daa6d

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ formatters:
55
- gofmt
66
- gofumpt
77
- goimports
8+
- gci
89
settings:
910
gofmt:
11+
simplify: true
1012
rewrite-rules:
1113
- pattern: interface{}
1214
replacement: any
@@ -15,6 +17,12 @@ formatters:
1517
goimports:
1618
local-prefixes:
1719
- github.com/go-task
20+
gci:
21+
sections:
22+
- standard
23+
- default
24+
- prefix(github.com/go-task)
25+
- localmodule
1826
exclusions:
1927
generated: lax
2028
paths:

Taskfile.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ tasks:
9898
cmds:
9999
- golangci-lint run --fix
100100

101+
format:
102+
desc: Runs golangci-lint and formats any Go files
103+
aliases: [fmt, f]
104+
sources:
105+
- './**/*.go'
106+
- .golangci.yml
107+
cmds:
108+
- golangci-lint fmt
109+
101110
sleepit:build:
102111
desc: Builds the sleepit test helper
103112
sources:

internal/templater/templater.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"maps"
77
"strings"
88

9+
"github.com/go-task/template"
10+
911
"github.com/go-task/task/v3/internal/deepcopy"
1012
"github.com/go-task/task/v3/taskfile/ast"
11-
"github.com/go-task/template"
1213
)
1314

1415
// Cache is a help struct that allow us to call "replaceX" funcs multiple

task.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"slices"
99
"sync/atomic"
1010

11+
"golang.org/x/sync/errgroup"
12+
"mvdan.cc/sh/v3/interp"
13+
1114
"github.com/go-task/task/v3/errors"
1215
"github.com/go-task/task/v3/internal/env"
1316
"github.com/go-task/task/v3/internal/execext"
@@ -19,9 +22,6 @@ import (
1922
"github.com/go-task/task/v3/internal/summary"
2023
"github.com/go-task/task/v3/internal/templater"
2124
"github.com/go-task/task/v3/taskfile/ast"
22-
23-
"golang.org/x/sync/errgroup"
24-
"mvdan.cc/sh/v3/interp"
2525
)
2626

2727
const (

task_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ func TestIncludesHttp(t *testing.T) {
933933

934934
for _, tc := range tcs {
935935
t.Run(tc.name, func(t *testing.T) {
936+
t.Parallel()
936937
task, err := e.CompiledTask(&task.Call{Task: tc.name})
937938
require.NoError(t, err)
938939
assert.Equal(t, tc.dir, task.Dir)

watch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ task: task "default" finished running
4949
dirPath := filepathext.SmartJoin(dir, "src")
5050
filePath := filepathext.SmartJoin(dirPath, "a")
5151

52-
err := os.MkdirAll(dirPath, 0755)
52+
err := os.MkdirAll(dirPath, 0o755)
5353
require.NoError(t, err)
5454

55-
err = os.WriteFile(filePath, []byte("test"), 0644)
55+
err = os.WriteFile(filePath, []byte("test"), 0o644)
5656
require.NoError(t, err)
5757

5858
ctx, cancel := context.WithCancel(context.Background())
@@ -72,7 +72,7 @@ task: task "default" finished running
7272
}()
7373

7474
time.Sleep(10 * time.Millisecond)
75-
err = os.WriteFile(filePath, []byte("test updated"), 0644)
75+
err = os.WriteFile(filePath, []byte("test updated"), 0o644)
7676
require.NoError(t, err)
7777

7878
time.Sleep(150 * time.Millisecond)

website/docs/contributing.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ Studio Code][vscode-task].
4343
## 2. Making changes
4444

4545
- **Code style** - Try to maintain the existing code style where possible. Go
46-
code should be formatted by [`gofumpt`][gofumpt] and linted using
47-
[`golangci-lint`][golangci-lint]. Any Markdown or TypeScript files should be
48-
formatted and linted by [Prettier][prettier]. This style is enforced by our CI
49-
to ensure that we have a consistent style across the project. You can use the
50-
`task lint` command to lint the code locally and the `task lint:fix` command
51-
to automatically fix any issues that are found.
46+
code should be formatted and linted by [`golangci-lint`][golangci-lint]. This
47+
wraps the [`gofumpt`][gofumpt] and [`gci`][gci] formatters and a number of
48+
linters. We recommend that you take a look at the [golangci-lint
49+
docs][golangci-lint-docs] for a guide on how to setup your editor to
50+
auto-format your code. Any Markdown or TypeScript files should be formatted
51+
and linted by [Prettier][prettier]. This style is enforced by our CI to ensure
52+
that we have a consistent style across the project. You can use the `task
53+
lint` command to lint the code locally and the `task lint:fix` command to try
54+
to automatically fix any issues that are found. You can also use the `task
55+
fmt` command to auto-format the files if your editor doesn't do it for you.
5256
- **Documentation** - Ensure that you add/update any relevant documentation. See
5357
the [updating documentation](#updating-documentation) section below.
5458
- **Tests** - Ensure that you add/update any relevant tests and that all tests
@@ -73,8 +77,9 @@ install the extension.
7377
Task uses [Docusaurus][docusaurus] to host a documentation server. The code for
7478
this is located in the core Task repository. This can be setup and run locally
7579
by using `task website` (requires `nodejs` & `yarn`). All content is written in
76-
Markdown and is located in the `website/docs` directory. All Markdown documents
77-
should have an 80 character line wrap limit (enforced by Prettier).
80+
[MDX][mdx] (an extension of Markdown) and is located in the `website/docs`
81+
directory. All Markdown documents should have an 80 character line wrap limit
82+
(enforced by Prettier).
7883

7984
When making a change, consider whether a change to the [Usage Guide](/usage) is
8085
necessary. This document contains descriptions and examples of how to use Task
@@ -154,7 +159,9 @@ If you have questions, feel free to ask them in the `#help` forum channel on our
154159
[vscode-task]: https://github.com/go-task/vscode-task
155160
[go]: https://go.dev
156161
[gofumpt]: https://github.com/mvdan/gofumpt
162+
[gci]: https://github.com/daixiang0/gci
157163
[golangci-lint]: https://golangci-lint.run
164+
[golangci-lint-docs]: https://golangci-lint.run/welcome/integrations/
158165
[prettier]: https://prettier.io
159166
[nodejs]: https://nodejs.org/en/
160167
[yarn]: https://yarnpkg.com/
@@ -166,4 +173,5 @@ If you have questions, feel free to ask them in the `#help` forum channel on our
166173
[discord-server]: https://discord.gg/6TY36E39UK
167174
[discussion]: https://github.com/go-task/task/discussions
168175
[conventional-commits]: https://www.conventionalcommits.org
176+
[mdx]: https://mdxjs.com/
169177
{/* prettier-ignore-end */}

0 commit comments

Comments
 (0)