Skip to content

Commit deb9613

Browse files
committed
t
1 parent 5632a08 commit deb9613

File tree

18 files changed

+3371
-1796
lines changed

18 files changed

+3371
-1796
lines changed

internal/linter/linter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func RunLinterInProgram(program *compiler.Program, allowFiles []string, skipFile
177177
var childVisitor ast.Visitor
178178
var patternVisitor func(node *ast.Node)
179179
patternVisitor = func(node *ast.Node) {
180+
runListeners(rule.WildcardTokenKind, node)
180181
runListeners(node.Kind, node)
181182
kind := rule.ListenerOnAllowPattern(node.Kind)
182183
runListeners(kind, node)
@@ -200,8 +201,10 @@ func RunLinterInProgram(program *compiler.Program, allowFiles []string, skipFile
200201

201202
runListeners(rule.ListenerOnExit(kind), node)
202203
runListeners(rule.ListenerOnExit(node.Kind), node)
204+
runListeners(rule.WildcardExitTokenKind, node)
203205
}
204206
childVisitor = func(node *ast.Node) bool {
207+
runListeners(rule.WildcardTokenKind, node)
205208
runListeners(node.Kind, node)
206209

207210
switch node.Kind {
@@ -222,6 +225,7 @@ func RunLinterInProgram(program *compiler.Program, allowFiles []string, skipFile
222225
}
223226

224227
runListeners(rule.ListenerOnExit(node.Kind), node)
228+
runListeners(rule.WildcardExitTokenKind, node)
225229

226230
return false
227231
}
Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +0,0 @@
1-
package rules_of_hooks
2-
3-
import (
4-
"github.com/microsoft/typescript-go/shim/ast"
5-
"github.com/web-infra-dev/rslint/internal/plugins/import/utils"
6-
"github.com/web-infra-dev/rslint/internal/rule"
7-
)
8-
9-
// Message functions for different error types
10-
func buildConditionalHookMessage(hookName string) rule.RuleMessage {
11-
return rule.RuleMessage{
12-
Id: "conditionalHook",
13-
Description: `React Hook "` + hookName + `" is called conditionally. React Hooks must be ` +
14-
"called in the exact same order in every component render.",
15-
}
16-
}
17-
18-
func buildLoopHookMessage(hookName string) rule.RuleMessage {
19-
return rule.RuleMessage{
20-
Id: "loopHook",
21-
Description: `React Hook "` + hookName + `" may be executed more than once. Possibly ` +
22-
"because it is called in a loop. React Hooks must be called in the " +
23-
"exact same order in every component render.",
24-
}
25-
}
26-
27-
func buildFunctionHookMessage(hookName, functionName string) rule.RuleMessage {
28-
return rule.RuleMessage{
29-
Id: "functionHook",
30-
Description: `React Hook "` + hookName + `" is called in function "` + functionName + `" that is neither ` +
31-
"a React function component nor a custom React Hook function." +
32-
" React component names must start with an uppercase letter." +
33-
" React Hook names must start with the word \"use\".",
34-
}
35-
}
36-
37-
func buildGenericHookMessage(hookName string) rule.RuleMessage {
38-
return rule.RuleMessage{
39-
Id: "genericHook",
40-
Description: `React Hook "` + hookName + `" cannot be called inside a callback. React Hooks ` +
41-
"must be called in a React function component or a custom React " +
42-
"Hook function.",
43-
}
44-
}
45-
46-
func buildTopLevelHookMessage(hookName string) rule.RuleMessage {
47-
return rule.RuleMessage{
48-
Id: "topLevelHook",
49-
Description: `React Hook "` + hookName + `" cannot be called at the top level. React Hooks ` +
50-
"must be called in a React function component or a custom React " +
51-
"Hook function.",
52-
}
53-
}
54-
55-
func buildClassHookMessage(hookName string) rule.RuleMessage {
56-
return rule.RuleMessage{
57-
Id: "classHook",
58-
Description: `React Hook "` + hookName + `" cannot be called in a class component. React Hooks ` +
59-
"must be called in a React function component or a custom React " +
60-
"Hook function.",
61-
}
62-
}
63-
64-
func buildAsyncComponentHookMessage(hookName string) rule.RuleMessage {
65-
return rule.RuleMessage{
66-
Id: "asyncComponentHook",
67-
Description: `React Hook "` + hookName + `" cannot be called in an async function.`,
68-
}
69-
}
70-
71-
func buildTryCatchUseMessage(hookName string) rule.RuleMessage {
72-
return rule.RuleMessage{
73-
Id: "tryCatchUse",
74-
Description: `React Hook "` + hookName + `" cannot be called inside a try/catch block.`,
75-
}
76-
}
77-
78-
var RulesOfHooksRule = rule.Rule{
79-
Name: "react-hooks/rules-of-hooks",
80-
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
81-
return utils.VisitModules(func(source, node *ast.Node) {
82-
83-
}, utils.VisitModulesOptions{
84-
Commonjs: true,
85-
ESModule: true,
86-
})
87-
},
88-
}

0 commit comments

Comments
 (0)