Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 32 additions & 1 deletion .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3993,7 +3993,22 @@ linters:
# Enable SQL builder checking.
# Default: true
check-sql-builders: false
# Regex patterns for acceptable SELECT * usage.
# Enable aliased wildcard detection like `SELECT t.*`.
# Default: true
check-aliased-wildcard: false
# Enable string concatenation analysis.
# Default: true
check-string-concat: false
# Enable format string analysis like `fmt.Sprintf`.
# Default: true
check-format-strings: false
# Enable strings.Builder analysis.
# Default: true
check-string-builder: false
# Enable subquery analysis.
# Default: true
check-subqueries: false
# Regex patterns for acceptable `SELECT *` usage.
# Default:
# - "SELECT \\* FROM information_schema\\..*"
# - "SELECT \\* FROM pg_catalog\\..*"
Expand All @@ -4003,6 +4018,22 @@ linters:
allowed-patterns:
- "SELECT \\* FROM temp_.*"
- "SELECT \\* FROM.*-- migration"
# Functions to ignore (regex patterns)
# Default: []
ignored-functions:
- "debug\\..*"
- "test.*"
# SQL builder libraries to check.
# Default: all true.
sql-builders:
squirrel: false
gorm: false
sqlx: false
ent: false
pgx: false
bun: false
sqlboiler: false
jet: false

unused:
# Mark all struct fields that have been written to as used.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/Antonboom/testifylint v1.6.4
github.com/BurntSushi/toml v1.6.0
github.com/Djarvur/go-err113 v0.1.1
github.com/MirrexOne/unqueryvet v1.3.0
github.com/MirrexOne/unqueryvet v1.4.0
github.com/OpenPeeDeeP/depguard/v2 v2.2.1
github.com/alecthomas/chroma/v2 v2.21.1
github.com/alecthomas/go-check-sumtype v0.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

70 changes: 70 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4083,12 +4083,82 @@
"type": "boolean",
"default": true
},
"check-aliased-wildcard": {
"description": "Enable aliased wildcard detection like SELECT t.*.",
"type": "boolean",
"default": true
},
"check-string-concat": {
"description": "Enable string concatenation analysis.",
"type": "boolean",
"default": true
},
"check-format-strings": {
"description": "Enable format string analysis like fmt.Sprintf.",
"type": "boolean",
"default": true
},
"check-string-builder": {
"description": "Enable strings.Builder analysis.",
"type": "boolean",
"default": true
},
"check-subqueries": {
"description": "Enable subquery analysis.",
"type": "boolean",
"default": true
},
"allowed-patterns": {
"description": "Regex patterns for acceptable SELECT * usage.",
"type": "array",
"items": {
"type": "string"
}
},
"ignored-functions": {
"description": "Functions to ignore.",
"type": "array",
"items": {
"type": "string"
}
},
"sql-builders": {
"type": "object",
"additionalProperties": false,
"properties": {
"squirrel": {
"type": "boolean",
"default": true
},
"gorm": {
"type": "boolean",
"default": true
},
"sqlx": {
"type": "boolean",
"default": true
},
"ent": {
"type": "boolean",
"default": true
},
"pgx": {
"type": "boolean",
"default": true
},
"bun": {
"type": "boolean",
"default": true
},
"sqlboiler": {
"type": "boolean",
"default": true
},
"jet": {
"type": "boolean",
"default": true
}
}
}
}
},
Expand Down
39 changes: 36 additions & 3 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,22 @@ var defaultLintersSettings = LintersSettings{
AllowPackages: []string{"main"},
},
Unqueryvet: UnqueryvetSettings{
CheckSQLBuilders: true,
CheckSQLBuilders: true,
CheckAliasedWildcard: true,
CheckStringConcat: true,
CheckFormatStrings: true,
CheckStringBuilder: true,
CheckSubqueries: true,
SQLBuilders: UnqueryvetSQLBuildersSettings{
Squirrel: true,
GORM: true,
SQLx: true,
Ent: true,
PGX: true,
Bun: true,
SQLBoiler: true,
Jet: true,
},
},
Unused: UnusedSettings{
FieldWritesAreUses: true,
Expand Down Expand Up @@ -1022,8 +1037,26 @@ type UnparamSettings struct {
}

type UnqueryvetSettings struct {
CheckSQLBuilders bool `mapstructure:"check-sql-builders"`
AllowedPatterns []string `mapstructure:"allowed-patterns"`
CheckSQLBuilders bool `mapstructure:"check-sql-builders"`
AllowedPatterns []string `mapstructure:"allowed-patterns"`
IgnoredFunctions []string `mapstructure:"ignored-functions"`
CheckAliasedWildcard bool `mapstructure:"check-aliased-wildcard"`
CheckStringConcat bool `mapstructure:"check-string-concat"`
CheckFormatStrings bool `mapstructure:"check-format-strings"`
CheckStringBuilder bool `mapstructure:"check-string-builder"`
CheckSubqueries bool `mapstructure:"check-subqueries"`
SQLBuilders UnqueryvetSQLBuildersSettings `mapstructure:"sql-builders"`
}

type UnqueryvetSQLBuildersSettings struct {
Squirrel bool `mapstructure:"squirrel"`
GORM bool `mapstructure:"gorm"`
SQLx bool `mapstructure:"sqlx"`
Ent bool `mapstructure:"ent"`
PGX bool `mapstructure:"pgx"`
Bun bool `mapstructure:"bun"`
SQLBoiler bool `mapstructure:"sqlboiler"`
Jet bool `mapstructure:"jet"`
}

type UnusedSettings struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/unqueryvet/testdata/unqueryvet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type SQLBuilder interface {
}

func _(builder SQLBuilder) {
query := builder.Select("*").From("products") // want "avoid SELECT \\* in SQL builder - explicitly specify columns to prevent unnecessary data transfer and schema change issues"
query := builder.Select("*").From("products") // want `Squirrel Select\(\"\*\"\) - explicitly specify columns`
_ = query
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/golinters/unqueryvet/unqueryvet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,29 @@ func New(settings *config.UnqueryvetSettings) *goanalysis.Linter {
cfg := pkgconfig.DefaultSettings()

if settings != nil {
// IgnoredFiles, and Severity are explicitly ignored.
cfg.CheckSQLBuilders = settings.CheckSQLBuilders
cfg.CheckAliasedWildcard = settings.CheckAliasedWildcard
cfg.CheckStringConcat = settings.CheckStringConcat
cfg.CheckFormatStrings = settings.CheckFormatStrings
cfg.CheckStringBuilder = settings.CheckStringBuilder
cfg.CheckSubqueries = settings.CheckSubqueries
cfg.IgnoredFunctions = settings.IgnoredFunctions

if len(settings.AllowedPatterns) > 0 {
cfg.AllowedPatterns = settings.AllowedPatterns
}

cfg.SQLBuilders = pkgconfig.SQLBuildersConfig{
Squirrel: settings.SQLBuilders.Squirrel,
GORM: settings.SQLBuilders.GORM,
SQLx: settings.SQLBuilders.SQLx,
Ent: settings.SQLBuilders.Ent,
PGX: settings.SQLBuilders.PGX,
Bun: settings.SQLBuilders.Bun,
SQLBoiler: settings.SQLBuilders.SQLBoiler,
Jet: settings.SQLBuilders.Jet,
}
}

return goanalysis.
Expand Down
Loading