Skip to content

Commit eabcccc

Browse files
authored
chore: use golanglint in ci (#147)
1 parent 06da73f commit eabcccc

File tree

10 files changed

+59
-12
lines changed

10 files changed

+59
-12
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ jobs:
3333
with:
3434
go-version: ${{ matrix.go-version }}
3535
cache-name: test-go
36+
- name: golangci-lint
37+
uses: golangci/golangci-lint-action@v8
38+
with:
39+
version: latest
40+
args: --timeout=5m ./cmd/... ./internal/...
3641
- name: go vet
3742
run: npm run lint:go
3843
- name: go fmt

.golangci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: '2'
2+
linters:
3+
enable:
4+
- govet # Go vet examiner
5+
- ineffassign # Detect ineffectual assignments
6+
7+
- unused # Check for unused constants, variables, functions and types
8+
- misspell # Finds commonly misspelled English words
9+
- unconvert # Remove unnecessary type conversions
10+
11+
disable:
12+
- errcheck # Check for unchecked errors
13+
- gosec # Inspects source code for security problems
14+
- staticcheck # It's a set of rules from staticcheck
15+
exclusions:
16+
generated: lax
17+
presets:
18+
- comments
19+
- common-false-positives
20+
- legacy
21+
- std-error-handling
22+
paths:
23+
- third_party$
24+
- builtin$
25+
- examples$
26+
issues:
27+
max-issues-per-linter: 0
28+
max-same-issues: 0
29+
new: false
30+
formatters:
31+
enable:
32+
- gofmt
33+
- goimports
34+
exclusions:
35+
generated: lax
36+
paths:
37+
- third_party$
38+
- builtin$
39+
- examples$

cmd/rslint/cmd.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,10 @@ func runCMD() int {
449449
w := bufio.NewWriterSize(os.Stdout, 4096*100)
450450
defer w.Flush()
451451
for d := range diagnosticsChan {
452-
if d.Severity == rule.SeverityError {
452+
switch d.Severity {
453+
case rule.SeverityError:
453454
errorsCount++
454-
} else if d.Severity == rule.SeverityWarning {
455+
case rule.SeverityWarning:
455456
warningsCount++
456457
}
457458

@@ -509,7 +510,7 @@ func runCMD() int {
509510

510511
if len(diagnosticsWithFixes) > 0 {
511512
// Read the original file content
512-
originalContent := string(diagnosticsWithFixes[0].SourceFile.Text())
513+
originalContent := diagnosticsWithFixes[0].SourceFile.Text()
513514

514515
// Apply fixes
515516
fixedContent, unapplied, wasFixed := linter.ApplyRuleFixes(originalContent, diagnosticsWithFixes)
@@ -600,10 +601,7 @@ func runCMD() int {
600601
}
601602
}
602603

603-
tooManyWarnings := false
604-
if maxWarnings >= 0 && warningsCount > maxWarnings {
605-
tooManyWarnings = true
606-
}
604+
tooManyWarnings := maxWarnings >= 0 && warningsCount > maxWarnings
607605

608606
if errorsCount == 0 && tooManyWarnings {
609607
fmt.Fprintf(os.Stderr, "Rslint found too many warnings (maximum: %d).\n", maxWarnings)

cmd/rslint/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func runMain() int {
2525
}
2626
}
2727
// run in CLI mode for direct command line usage
28-
return int(runCMD())
28+
return runCMD()
2929
}

internal/rules/no_base_to_string/no_base_to_string.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func certaintyToString(certainty usefulness) string {
1919
case usefulnessSometimes:
2020
return "always"
2121
default:
22-
panic("unkown certainty")
22+
panic("unknown certainty")
2323
}
2424
}
2525

internal/rules/no_misused_promises/no_misused_promises.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func buildPredicateMessage() rule.RuleMessage {
2525
func buildSpreadMessage() rule.RuleMessage {
2626
return rule.RuleMessage{
2727
Id: "spread",
28-
Description: "Expected a non-Promise value to be spreaded in an object.",
28+
Description: "Expected a non-Promise value to be spread in an object.",
2929
}
3030
}
3131
func buildVoidReturnArgumentMessage() rule.RuleMessage {

internal/rules/no_unsafe_enum_comparison/no_unsafe_enum_comparison.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func buildMismatchedConditionMessage() rule.RuleMessage {
2121
Description: "The two values in this comparison do not have a shared enum type.",
2222
}
2323
}
24+
25+
//nolint:unused
2426
func buildReplaceValueWithEnumMessage() rule.RuleMessage {
2527
return rule.RuleMessage{
2628
Id: "replaceValueWithEnum",

internal/rules/require_await/require_await.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ func buildMissingAwaitMessage() rule.RuleMessage {
1313
Description: "Function has no 'await' expression.",
1414
}
1515
}
16+
17+
//nolint:unused
1618
func buildRemoveAsyncMessage() rule.RuleMessage {
1719
return rule.RuleMessage{
1820
Id: "removeAsync",

internal/rules/switch_exhaustiveness_check/switch_exhaustiveness_check.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/web-infra-dev/rslint/internal/utils"
1111
)
1212

13+
//nolint:unused
1314
func buildAddMissingCasesMessage() rule.RuleMessage {
1415
return rule.RuleMessage{
1516
Id: "addMissingCases",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"test:go": "go test ./internal/...",
2626
"typecheck": "pnpm tsc -b tsconfig.json",
2727
"lint": "rslint",
28-
"lint:go": "go vet ./cmd/... ./internal/...",
29-
"format:go": "go fmt ./cmd/... ./internal/...",
28+
"lint:go": "golangci-lint run ./cmd/... ./internal/...",
29+
"format:go": "golangci-lint fmt ./cmd/... ./internal/...",
3030
"prepare": "husky"
3131
},
3232
"devDependencies": {

0 commit comments

Comments
 (0)