Skip to content

Commit b5ae69b

Browse files
Ajit Pratap SinghAjit Pratap Singh
authored andcommitted
fix: architect review quick wins (rules filter, WASM CI, expanded lint)
1 parent 838d0e1 commit b5ae69b

File tree

10 files changed

+68
-26
lines changed

10 files changed

+68
-26
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
- name: Build
2525
run: go build -v ./...
2626

27+
- name: Build WASM
28+
run: GOOS=js GOARCH=wasm go build -o /dev/null ./wasm/
29+
2730
test:
2831
name: Test
2932
runs-on: ${{ matrix.os }}

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ linters:
1111
- errcheck
1212
- govet
1313
- staticcheck
14+
- misspell
15+
- gocritic
1416
settings:
1517
errcheck:
1618
exclude-functions:
@@ -25,6 +27,9 @@ linters:
2527
- "all"
2628
- "-QF*"
2729
- "-ST*"
30+
gocritic:
31+
disabled-checks:
32+
- ifElseChain
2833

2934
issues:
3035
max-issues-per-linter: 0

cmd/gosqlx/cmd/action.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,40 @@ func defaultLinter() *linter.Linter {
303303
)
304304
}
305305

306+
// allRules returns every built-in rule keyed by its ID.
307+
func allRules() map[string]linter.Rule {
308+
all := []linter.Rule{
309+
whitespace.NewTrailingWhitespaceRule(),
310+
whitespace.NewMixedIndentationRule(),
311+
keywords.NewKeywordCaseRule(keywords.CaseUpper),
312+
style.NewColumnAlignmentRule(),
313+
}
314+
m := make(map[string]linter.Rule, len(all))
315+
for _, r := range all {
316+
m[r.ID()] = r
317+
}
318+
return m
319+
}
320+
306321
// lintFile runs the linter on a file and returns violations.
307-
func lintFile(filePath string, _ []string) []lintViolation {
308-
l := defaultLinter()
322+
// When ruleList is non-empty only the rules whose IDs match are executed.
323+
func lintFile(filePath string, ruleList []string) []lintViolation {
324+
var l *linter.Linter
325+
if len(ruleList) == 0 {
326+
l = defaultLinter()
327+
} else {
328+
available := allRules()
329+
var selected []linter.Rule
330+
for _, id := range ruleList {
331+
if r, ok := available[id]; ok {
332+
selected = append(selected, r)
333+
}
334+
}
335+
if len(selected) == 0 {
336+
return nil
337+
}
338+
l = linter.New(selected...)
339+
}
309340
result := l.LintFile(filePath)
310341

311342
if result.Error != nil {

cmd/gosqlx/cmd/parser_cmd.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ func (p *Parser) displayTree(astObj *ast.AST) error {
257257

258258
fmt.Fprintf(p.Out, "%s %s\n", prefix, stmtType)
259259

260-
// Add basic tree structure for different statement types
261-
switch s := stmt.(type) {
262-
case *ast.SelectStatement:
260+
// Add basic tree structure for SELECT statements
261+
if s, ok := stmt.(*ast.SelectStatement); ok {
263262
if len(s.Columns) > 0 {
264263
fmt.Fprintf(p.Out, "%s├── Columns (%d items)\n", childPrefix, len(s.Columns))
265264
}

examples/distinct_on_example.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,29 @@ func main() {
8282

8383
func parseAndDisplay(tokens []token.Token) {
8484
p := parser.NewParser()
85-
defer p.Release()
8685

8786
astObj, err := p.Parse(tokens)
8887
if err != nil {
88+
p.Release()
8989
log.Fatalf("Parse error: %v", err)
9090
}
91+
92+
displayAST(p, astObj)
93+
}
94+
95+
func displayAST(p *parser.Parser, astObj *ast.AST) {
96+
defer p.Release()
9197
defer ast.ReleaseAST(astObj)
9298

9399
if len(astObj.Statements) == 0 {
94-
log.Fatal("No statements parsed")
100+
fmt.Println("No statements parsed")
101+
return
95102
}
96103

97104
stmt, ok := astObj.Statements[0].(*ast.SelectStatement)
98105
if !ok {
99-
log.Fatalf("Expected SelectStatement, got %T", astObj.Statements[0])
106+
fmt.Printf("Expected SelectStatement, got %T\n", astObj.Statements[0])
107+
return
100108
}
101109

102110
fmt.Println("Parsed Successfully!")

pkg/advisor/rules.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ func hasJoinCondition(expr ast.Expression, tableNames []string) bool {
171171
return false
172172
}
173173

174-
switch e := expr.(type) {
175-
case *ast.BinaryExpression:
174+
if e, ok := expr.(*ast.BinaryExpression); ok {
176175
if e.Operator == "AND" || e.Operator == "OR" {
177176
return hasJoinCondition(e.Left, tableNames) || hasJoinCondition(e.Right, tableNames)
178177
}
@@ -376,8 +375,7 @@ func containsOrCondition(expr ast.Expression) bool {
376375
return false
377376
}
378377

379-
switch e := expr.(type) {
380-
case *ast.BinaryExpression:
378+
if e, ok := expr.(*ast.BinaryExpression); ok {
381379
if strings.EqualFold(e.Operator, "OR") {
382380
// Check if the OR operates on different columns
383381
leftCols := collectColumnNames(e.Left)

pkg/config/lsp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ func ValidateLSPValue(section, key string, value interface{}) error {
392392
}
393393

394394
case "gosqlx.server":
395-
switch key {
396-
case "logLevel":
395+
if key == "logLevel" {
397396
if v, ok := value.(string); ok {
398397
config.Server.LogLevel = v
399398
} else {

pkg/linter/rules/keywords/keyword_case.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,13 @@ func tokenizeLine(line string) []wordToken {
206206
wordStart = i
207207
}
208208
currentWord.WriteRune(ch)
209-
} else {
210-
if wordStart >= 0 {
211-
words = append(words, wordToken{
212-
text: currentWord.String(),
213-
column: wordStart + 1, // 1-indexed
214-
})
215-
currentWord.Reset()
216-
wordStart = -1
217-
}
209+
} else if wordStart >= 0 {
210+
words = append(words, wordToken{
211+
text: currentWord.String(),
212+
column: wordStart + 1, // 1-indexed
213+
})
214+
currentWord.Reset()
215+
wordStart = -1
218216
}
219217
}
220218

pkg/sql/ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ type UpdateStatement struct {
12071207
}
12081208

12091209
// GetUpdates returns Assignments for backward compatibility.
1210+
//
12101211
// Deprecated: Use Assignments directly instead.
12111212
func (u *UpdateStatement) GetUpdates() []UpdateExpression {
12121213
return u.Assignments

pkg/sql/ast/value.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ const (
256256
Julian
257257
Microsecond
258258
Microseconds
259-
Millenium
259+
Millenium //nolint:misspell // intentional: SQL accepts both spellings
260260
Millennium
261261
Millisecond
262262
Milliseconds
@@ -333,8 +333,8 @@ func (d DateTimeField) String() string {
333333
return "MICROSECOND"
334334
case Microseconds:
335335
return "MICROSECONDS"
336-
case Millenium:
337-
return "MILLENIUM"
336+
case Millenium: //nolint:misspell // intentional: SQL accepts both spellings
337+
return "MILLENIUM" //nolint:misspell // intentional: matches SQL keyword
338338
case Millennium:
339339
return "MILLENNIUM"
340340
case Millisecond:

0 commit comments

Comments
 (0)