Skip to content

Commit e366eaf

Browse files
committed
feat: add options schema for no-base-to-string and no-confusing-void-expression (#392)
Admittedly, I meant to split this into two PRs but accidentally put it in one, and I don't feel like splitting it back so we're just gonna roll with it.
1 parent 2626b2e commit e366eaf

File tree

7 files changed

+188
-92
lines changed

7 files changed

+188
-92
lines changed

internal/rules/no_base_to_string/no_base_to_string.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ func buildBaseToStringMessage(name string, certainty usefulness) rule.RuleMessag
3636
}
3737
}
3838

39-
type NoBaseToStringOptions struct {
40-
IgnoredTypeNames []string
41-
}
42-
4339
type usefulness uint32
4440

4541
const (
@@ -51,12 +47,7 @@ const (
5147
var NoBaseToStringRule = rule.Rule{
5248
Name: "no-base-to-string",
5349
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
54-
opts, ok := options.(NoBaseToStringOptions)
55-
if !ok {
56-
opts = NoBaseToStringOptions{
57-
IgnoredTypeNames: []string{"Error", "RegExp", "URL", "URLSearchParams"},
58-
}
59-
}
50+
opts := utils.UnmarshalOptions[NoBaseToStringOptions](options, "no-base-to-string")
6051

6152
var collectToStringCertainty func(
6253
t *checker.Type,

internal/rules/no_base_to_string/options.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://json-schema.org/draft-07/schema#",
3+
"definitions": {
4+
"no_base_to_string_options": {
5+
"type": "object",
6+
"properties": {
7+
"ignoredTypeNames": {
8+
"type": "array",
9+
"items": {
10+
"type": "string"
11+
},
12+
"default": ["Error", "RegExp", "URL", "URLSearchParams"]
13+
}
14+
}
15+
}
16+
}
17+
}

internal/rules/no_confusing_void_expression/no_confusing_void_expression.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,10 @@ func buildVoidExprWrapVoidMessage() rule.RuleMessage {
5757
}
5858
}
5959

60-
type NoConfusingVoidExpressionOptions struct {
61-
IgnoreArrowShorthand bool
62-
IgnoreVoidOperator bool
63-
IgnoreVoidReturningFunctions bool
64-
}
65-
6660
var NoConfusingVoidExpressionRule = rule.Rule{
6761
Name: "no-confusing-void-expression",
6862
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
69-
opts, ok := options.(NoConfusingVoidExpressionOptions)
70-
if !ok {
71-
opts = NoConfusingVoidExpressionOptions{}
72-
}
63+
opts := utils.UnmarshalOptions[NoConfusingVoidExpressionOptions](options, "no-confusing-void-expression")
7364

7465
canFix := func(node *ast.Node) bool {
7566
t := utils.GetConstrainedTypeAtLocation(ctx.TypeChecker, node)

0 commit comments

Comments
 (0)