Skip to content

Commit 7fba90e

Browse files
authored
refactor: use createRule to defineRule (#161)
1 parent b774696 commit 7fba90e

File tree

66 files changed

+517
-518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+517
-518
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: golangci-lint
4242
uses: golangci/golangci-lint-action@v8
4343
with:
44-
version: latest
44+
version: v2.3.0
4545
args: --timeout=5m ./cmd/... ./internal/...
4646
- name: go vet
4747
run: npm run lint:go

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ linters:
3737
- misspell
3838
- musttag
3939
- nakedret
40-
- nolintlint
40+
# - nolintlint
4141
- paralleltest
4242
- perfsprint
4343
- predeclared

cmd/rslint/lsp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *LSPServer) handleInitialize(ctx context.Context, req *jsonrpc2.Request)
9595
if err := json.Unmarshal(*req.Params, &params); err != nil {
9696
s.rootURI = "."
9797
} else {
98-
//nolint:staticcheck
98+
//nolint
9999
if params.RootUri.DocumentUri != nil {
100100
s.rootURI = uriToPath(string(*params.RootUri.DocumentUri))
101101
}

internal/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ func getAllTypeScriptEslintPluginRules() []rule.Rule {
318318
allRules := GlobalRuleRegistry.GetAllRules()
319319
var rules []rule.Rule
320320
for _, rule := range allRules {
321-
rule.Name = "@typescript-eslint/" + rule.Name
322321
rules = append(rules, rule)
323322
}
324323
return rules

internal/linter/linter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func RunLinter(programs []*compiler.Program, singleThreaded bool, allowFiles []s
5959
rules := getRulesForFile(file)
6060
// Create disable manager for this file
6161
disableManager := rule.NewDisableManager(file)
62-
62+
6363
for _, r := range rules {
6464
ctx := rule.RuleContext{
6565
SourceFile: file,

internal/rule/disable_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const (
2727
// DisableManager tracks which rules are disabled at different locations in a file
2828
type DisableManager struct {
2929
sourceFile *ast.SourceFile
30-
disabledRules map[string]bool // Rules disabled for the entire file
31-
lineDisabledRules map[int][]string // Rules disabled for specific lines
32-
nextLineDisabledRules map[int][]string // Rules disabled for the next line
30+
disabledRules map[string]bool // Rules disabled for the entire file
31+
lineDisabledRules map[int][]string // Rules disabled for specific lines
32+
nextLineDisabledRules map[int][]string // Rules disabled for the next line
3333
}
3434

3535
// NewDisableManager creates a new DisableManager for the given source file

internal/rule/rule.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ type Rule struct {
8787
Run func(ctx RuleContext, options any) RuleListeners
8888
}
8989

90+
func CreateRule(r Rule) Rule {
91+
return Rule{
92+
Name: "@typescript-eslint/" + r.Name,
93+
Run: r.Run,
94+
}
95+
}
96+
9097
type RuleMessage struct {
9198
Id string
9299
Description string
@@ -158,7 +165,7 @@ type RuleContext struct {
158165
SourceFile *ast.SourceFile
159166
Program *compiler.Program
160167
TypeChecker *checker.Checker
161-
DisableManager *DisableManager
168+
DisableManager *DisableManager
162169
ReportRange func(textRange core.TextRange, msg RuleMessage)
163170
ReportRangeWithSuggestions func(textRange core.TextRange, msg RuleMessage, suggestions ...RuleSuggestion)
164171
ReportNode func(node *ast.Node, msg RuleMessage)

internal/rules/adjacent_overload_signatures/adjacent_overload_signatures.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func checkBodyForOverloadMethods(ctx rule.RuleContext, node *ast.Node) {
180180
}
181181
}
182182

183-
var AdjacentOverloadSignaturesRule = rule.Rule{
183+
var AdjacentOverloadSignaturesRule = rule.CreateRule(rule.Rule{
184184
Name: "adjacent-overload-signatures",
185185
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
186186
// Check the source file at the beginning
@@ -204,4 +204,4 @@ var AdjacentOverloadSignaturesRule = rule.Rule{
204204
},
205205
}
206206
},
207-
}
207+
})

internal/rules/array_type/array_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func buildErrorStringGenericSimpleMessage(readonlyPrefix, typeStr, className str
143143
}
144144
}
145145

146-
var ArrayTypeRule = rule.Rule{
146+
var ArrayTypeRule = rule.CreateRule(rule.Rule{
147147
Name: "array-type",
148148
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
149149
opts := ArrayTypeOptions{
@@ -438,4 +438,4 @@ var ArrayTypeRule = rule.Rule{
438438
},
439439
}
440440
},
441-
}
441+
})

internal/rules/await_thenable/await_thenable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func buildAwaitUsingOfNonAsyncDisposableMessage() rule.RuleMessage {
4242
}
4343
}
4444

45-
var AwaitThenableRule = rule.Rule{
45+
var AwaitThenableRule = rule.CreateRule(rule.Rule{
4646
Name: "await-thenable",
4747
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
4848
return rule.RuleListeners{
@@ -131,4 +131,4 @@ var AwaitThenableRule = rule.Rule{
131131
},
132132
}
133133
},
134-
}
134+
})

0 commit comments

Comments
 (0)