diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da6035e5..e675ff62 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: - name: Install Go uses: actions/setup-go@v5 with: - go-version: stable + go-version: '1.24' - name: Git checkout uses: actions/checkout@v4 - name: Build diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index bb05c462..5eeff723 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,8 +16,8 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: stable + go-version: '1.24' - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.61 + version: v2.0 diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 7853fdc4..7a9ba9a1 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -18,7 +18,7 @@ jobs: name: Set up Go uses: actions/setup-go@v5 with: - go-version: stable + go-version: '1.24' - name: Release uses: goreleaser/goreleaser-action@v6 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..d454e3ed --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,6 @@ +version: "2" +linters: + exclusions: + rules: + - path: rule_gen\.go + text: "QF1001:" diff --git a/goi18n/common_test.go b/goi18n/common_test.go index a86764b9..6bbd2d0e 100644 --- a/goi18n/common_test.go +++ b/goi18n/common_test.go @@ -1,6 +1,9 @@ package main -import "os" +import ( + "os" + "testing" +) func mustTempDir(prefix string) string { outdir, err := os.MkdirTemp("", prefix) @@ -9,3 +12,9 @@ func mustTempDir(prefix string) string { } return outdir } + +func mustRemoveAll(t *testing.T, path string) { + if err := os.RemoveAll(path); err != nil { + t.Fatal(err) + } +} diff --git a/goi18n/extract_command_test.go b/goi18n/extract_command_test.go index bc835139..a841fdaa 100644 --- a/goi18n/extract_command_test.go +++ b/goi18n/extract_command_test.go @@ -290,9 +290,9 @@ zero = "Zero translation" for _, test := range tests { t.Run(test.name, func(t *testing.T) { indir := mustTempDir("TestExtractCommandIn") - defer os.RemoveAll(indir) + defer mustRemoveAll(t, indir) outdir := mustTempDir("TestExtractCommandOut") - defer os.RemoveAll(outdir) + defer mustRemoveAll(t, outdir) inpath := filepath.Join(indir, test.fileName) if err := os.WriteFile(inpath, []byte(test.file), 0666); err != nil { @@ -342,7 +342,7 @@ func TestExtractCommand(t *testing.T) { if err != nil { t.Fatal(err) } - defer os.RemoveAll(outdir) + defer mustRemoveAll(t, outdir) if code := testableMain([]string{"extract", "-outdir", outdir, "../example/"}); code != 0 { t.Fatalf("expected exit code 0; got %d", code) } diff --git a/goi18n/merge_command.go b/goi18n/merge_command.go index c95ee90a..1eaae9de 100644 --- a/goi18n/merge_command.go +++ b/goi18n/merge_command.go @@ -99,7 +99,7 @@ func (mc *mergeCommand) execute() error { } for _, path := range ops.deleteFiles { // Ignore error since it isn't guaranteed to exist. - os.Remove(path) + _ = os.Remove(path) } return nil } diff --git a/goi18n/merge_command_test.go b/goi18n/merge_command_test.go index 5afad7bb..ad3bd966 100644 --- a/goi18n/merge_command_test.go +++ b/goi18n/merge_command_test.go @@ -530,9 +530,9 @@ zero = "{{.Count}} unread emails" for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { indir := mustTempDir("TestMergeCommandIn") - defer os.RemoveAll(indir) + defer mustRemoveAll(t, indir) outdir := mustTempDir("TestMergeCommandOut") - defer os.RemoveAll(outdir) + defer mustRemoveAll(t, outdir) infiles := make([]string, 0, len(testCase.inFiles)) for name, content := range testCase.inFiles { diff --git a/i18n/message_template.go b/i18n/message_template.go index 24a890b8..4bb6c605 100644 --- a/i18n/message_template.go +++ b/i18n/message_template.go @@ -61,7 +61,7 @@ func (mt *MessageTemplate) Execute(pluralForm plural.Form, data interface{}, fun if t == nil { return "", pluralFormNotFoundError{ pluralForm: pluralForm, - messageID: mt.Message.ID, + messageID: mt.ID, } } parser := &template.TextParser{ @@ -75,7 +75,7 @@ func (mt *MessageTemplate) execute(pluralForm plural.Form, data interface{}, par if t == nil { return "", pluralFormNotFoundError{ pluralForm: pluralForm, - messageID: mt.Message.ID, + messageID: mt.ID, } } return t.Execute(parser, data) diff --git a/internal/plural/codegen/xml.go b/internal/plural/codegen/xml.go index 3560e6d3..3d80fe0f 100644 --- a/internal/plural/codegen/xml.go +++ b/internal/plural/codegen/xml.go @@ -26,7 +26,7 @@ type PluralGroup struct { // Name returns a unique name for this plural group. func (pg *PluralGroup) Name() string { n := cases.Title(language.AmericanEnglish).String(pg.Locales) - return strings.Replace(n, " ", "", -1) + return strings.ReplaceAll(n, " ", "") } // SplitLocales returns all the locales in the PluralGroup as a slice.