1
0
mirror of https://github.com/go-task/task.git synced 2025-10-08 23:02:02 +02:00

feat: formatting with golangci-lint and gci

This commit is contained in:
Pete Davison
2025-04-27 20:38:13 +00:00
parent 20c1ffe098
commit 13daa6dc35
7 changed files with 42 additions and 15 deletions

View File

@@ -5,8 +5,10 @@ formatters:
- gofmt - gofmt
- gofumpt - gofumpt
- goimports - goimports
- gci
settings: settings:
gofmt: gofmt:
simplify: true
rewrite-rules: rewrite-rules:
- pattern: interface{} - pattern: interface{}
replacement: any replacement: any
@@ -15,6 +17,12 @@ formatters:
goimports: goimports:
local-prefixes: local-prefixes:
- github.com/go-task - github.com/go-task
gci:
sections:
- standard
- default
- prefix(github.com/go-task)
- localmodule
exclusions: exclusions:
generated: lax generated: lax
paths: paths:

View File

@@ -98,6 +98,15 @@ tasks:
cmds: cmds:
- golangci-lint run --fix - golangci-lint run --fix
format:
desc: Runs golangci-lint and formats any Go files
aliases: [fmt, f]
sources:
- './**/*.go'
- .golangci.yml
cmds:
- golangci-lint fmt
sleepit:build: sleepit:build:
desc: Builds the sleepit test helper desc: Builds the sleepit test helper
sources: sources:

View File

@@ -6,9 +6,10 @@ import (
"maps" "maps"
"strings" "strings"
"github.com/go-task/template"
"github.com/go-task/task/v3/internal/deepcopy" "github.com/go-task/task/v3/internal/deepcopy"
"github.com/go-task/task/v3/taskfile/ast" "github.com/go-task/task/v3/taskfile/ast"
"github.com/go-task/template"
) )
// Cache is a help struct that allow us to call "replaceX" funcs multiple // Cache is a help struct that allow us to call "replaceX" funcs multiple

View File

@@ -8,6 +8,9 @@ import (
"slices" "slices"
"sync/atomic" "sync/atomic"
"golang.org/x/sync/errgroup"
"mvdan.cc/sh/v3/interp"
"github.com/go-task/task/v3/errors" "github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/env" "github.com/go-task/task/v3/internal/env"
"github.com/go-task/task/v3/internal/execext" "github.com/go-task/task/v3/internal/execext"
@@ -19,9 +22,6 @@ import (
"github.com/go-task/task/v3/internal/summary" "github.com/go-task/task/v3/internal/summary"
"github.com/go-task/task/v3/internal/templater" "github.com/go-task/task/v3/internal/templater"
"github.com/go-task/task/v3/taskfile/ast" "github.com/go-task/task/v3/taskfile/ast"
"golang.org/x/sync/errgroup"
"mvdan.cc/sh/v3/interp"
) )
const ( const (

View File

@@ -933,6 +933,7 @@ func TestIncludesHttp(t *testing.T) {
for _, tc := range tcs { for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
t.Parallel()
task, err := e.CompiledTask(&task.Call{Task: tc.name}) task, err := e.CompiledTask(&task.Call{Task: tc.name})
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, tc.dir, task.Dir) assert.Equal(t, tc.dir, task.Dir)

View File

@@ -49,10 +49,10 @@ task: task "default" finished running
dirPath := filepathext.SmartJoin(dir, "src") dirPath := filepathext.SmartJoin(dir, "src")
filePath := filepathext.SmartJoin(dirPath, "a") filePath := filepathext.SmartJoin(dirPath, "a")
err := os.MkdirAll(dirPath, 0755) err := os.MkdirAll(dirPath, 0o755)
require.NoError(t, err) require.NoError(t, err)
err = os.WriteFile(filePath, []byte("test"), 0644) err = os.WriteFile(filePath, []byte("test"), 0o644)
require.NoError(t, err) require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@@ -72,7 +72,7 @@ task: task "default" finished running
}() }()
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
err = os.WriteFile(filePath, []byte("test updated"), 0644) err = os.WriteFile(filePath, []byte("test updated"), 0o644)
require.NoError(t, err) require.NoError(t, err)
time.Sleep(150 * time.Millisecond) time.Sleep(150 * time.Millisecond)

View File

@@ -43,12 +43,16 @@ Studio Code][vscode-task].
## 2. Making changes ## 2. Making changes
- **Code style** - Try to maintain the existing code style where possible. Go - **Code style** - Try to maintain the existing code style where possible. Go
code should be formatted by [`gofumpt`][gofumpt] and linted using code should be formatted and linted by [`golangci-lint`][golangci-lint]. This
[`golangci-lint`][golangci-lint]. Any Markdown or TypeScript files should be wraps the [`gofumpt`][gofumpt] and [`gci`][gci] formatters and a number of
formatted and linted by [Prettier][prettier]. This style is enforced by our CI linters. We recommend that you take a look at the [golangci-lint
to ensure that we have a consistent style across the project. You can use the docs][golangci-lint-docs] for a guide on how to setup your editor to
`task lint` command to lint the code locally and the `task lint:fix` command auto-format your code. Any Markdown or TypeScript files should be formatted
to automatically fix any issues that are found. and linted by [Prettier][prettier]. This style is enforced by our CI to ensure
that we have a consistent style across the project. You can use the `task
lint` command to lint the code locally and the `task lint:fix` command to try
to automatically fix any issues that are found. You can also use the `task
fmt` command to auto-format the files if your editor doesn't do it for you.
- **Documentation** - Ensure that you add/update any relevant documentation. See - **Documentation** - Ensure that you add/update any relevant documentation. See
the [updating documentation](#updating-documentation) section below. the [updating documentation](#updating-documentation) section below.
- **Tests** - Ensure that you add/update any relevant tests and that all tests - **Tests** - Ensure that you add/update any relevant tests and that all tests
@@ -73,8 +77,9 @@ install the extension.
Task uses [Docusaurus][docusaurus] to host a documentation server. The code for Task uses [Docusaurus][docusaurus] to host a documentation server. The code for
this is located in the core Task repository. This can be setup and run locally this is located in the core Task repository. This can be setup and run locally
by using `task website` (requires `nodejs` & `yarn`). All content is written in by using `task website` (requires `nodejs` & `yarn`). All content is written in
Markdown and is located in the `website/docs` directory. All Markdown documents [MDX][mdx] (an extension of Markdown) and is located in the `website/docs`
should have an 80 character line wrap limit (enforced by Prettier). directory. All Markdown documents should have an 80 character line wrap limit
(enforced by Prettier).
When making a change, consider whether a change to the [Usage Guide](/usage) is When making a change, consider whether a change to the [Usage Guide](/usage) is
necessary. This document contains descriptions and examples of how to use Task 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
[vscode-task]: https://github.com/go-task/vscode-task [vscode-task]: https://github.com/go-task/vscode-task
[go]: https://go.dev [go]: https://go.dev
[gofumpt]: https://github.com/mvdan/gofumpt [gofumpt]: https://github.com/mvdan/gofumpt
[gci]: https://github.com/daixiang0/gci
[golangci-lint]: https://golangci-lint.run [golangci-lint]: https://golangci-lint.run
[golangci-lint-docs]: https://golangci-lint.run/welcome/integrations/
[prettier]: https://prettier.io [prettier]: https://prettier.io
[nodejs]: https://nodejs.org/en/ [nodejs]: https://nodejs.org/en/
[yarn]: https://yarnpkg.com/ [yarn]: https://yarnpkg.com/
@@ -166,4 +173,5 @@ If you have questions, feel free to ask them in the `#help` forum channel on our
[discord-server]: https://discord.gg/6TY36E39UK [discord-server]: https://discord.gg/6TY36E39UK
[discussion]: https://github.com/go-task/task/discussions [discussion]: https://github.com/go-task/task/discussions
[conventional-commits]: https://www.conventionalcommits.org [conventional-commits]: https://www.conventionalcommits.org
[mdx]: https://mdxjs.com/
{/* prettier-ignore-end */} {/* prettier-ignore-end */}