Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add untypedconst linter#3527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
leonklingele wants to merge1 commit intogolangci:master
base:master
Choose a base branch
Loading
fromleonklingele:feat-add-untypedconst
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions.golangci.next.reference.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,6 +111,7 @@ linters:
- tparallel
- unconvert
- unparam
- untypedconst
- unused
- usestdlibvars
- usetesting
Expand DownExpand Up@@ -227,6 +228,7 @@ linters:
- tparallel
- unconvert
- unparam
- untypedconst
- unused
- usestdlibvars
- usetesting
Expand Down
1 change: 1 addition & 0 deletionsgo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,7 @@ require (
github.com/gostaticanalysis/nilerr v0.1.1
github.com/hashicorp/go-version v1.7.0
github.com/jgautheron/goconst v1.7.1
github.com/jiftechnify/untypedconst v0.1.0
github.com/jingyugao/rowserrcheck v1.1.1
github.com/jjti/go-spancheck v0.6.4
github.com/julz/importas v0.2.0
Expand Down
16 changes: 16 additions & 0 deletionsgo.sum
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

67 changes: 67 additions & 0 deletionspkg/golinters/untypedconst/testdata/untypedconst.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
//golangcitest:args -Euntypedconst
package testdata

import (
"fmt"
)

type ExString string

func retExString() ExString {
if true {
return ExString("hoge")
} else {
fmt.Println("This should never happen")
return "hoge" // want `returning untyped constant as defined type "command-line-arguments.ExString"`
}
}

type ExInt int

func retExInt() ExInt {
if true {
return ExInt(1)
} else {
return 1 // want `returning untyped constant as defined type "command-line-arguments.ExInt"`
}
}

type ExFloat float64

func retExFloat() ExFloat {
if true {
return ExFloat(0.5)
} else {
return 0.5 // want `returning untyped constant as defined type "command-line-arguments.ExFloat"`
}
}

type ExComplex complex128

func retExComplex() ExComplex {
if true {
return ExComplex(1.0 + 0.5i)
} else {
return 1.0 + 0.5i // want `returning untyped constant as defined type "command-line-arguments.ExComplex"`
}
}

type ExRune rune

func retExRune() ExRune {
if true {
return ExRune('a')
} else {
return 'a' // want `returning untyped constant as defined type "command-line-arguments.ExRune"`
}
}

type ExBool bool

func retExBool() ExBool {
if true {
return ExBool(true)
} else {
return true // want `returning untyped constant as defined type "command-line-arguments.ExBool"`
}
}
19 changes: 19 additions & 0 deletionspkg/golinters/untypedconst/untypedconst.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
package untypedconst

import (
"github.com/jiftechnify/untypedconst"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func New() *goanalysis.Linter {
a := untypedconst.Analyzer

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
7 changes: 7 additions & 0 deletionspkg/lint/lintersdb/builder_linter.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -104,6 +104,7 @@ import (
"github.com/golangci/golangci-lint/pkg/golinters/tparallel"
"github.com/golangci/golangci-lint/pkg/golinters/unconvert"
"github.com/golangci/golangci-lint/pkg/golinters/unparam"
"github.com/golangci/golangci-lint/pkg/golinters/untypedconst"
"github.com/golangci/golangci-lint/pkg/golinters/unused"
"github.com/golangci/golangci-lint/pkg/golinters/usestdlibvars"
"github.com/golangci/golangci-lint/pkg/golinters/usetesting"
Expand DownExpand Up@@ -817,6 +818,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithLoadForGoAnalysis().
WithURL("https://github.com/mvdan/unparam"),

linter.NewConfig(untypedconst.New()).
WithSince("v1.65.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/jiftechnify/untypedconst"),

linter.NewConfig(unused.New(&cfg.LintersSettings.Unused)).
WithEnabledByDefault().
WithSince("v1.20.0").
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp