Skip to content

Commit 96db70a

Browse files
authored
chore: passing more case (#173)
1 parent 01405eb commit 96db70a

File tree

8 files changed

+2036
-13
lines changed

8 files changed

+2036
-13
lines changed

internal/rules/no_confusing_void_expression/no_confusing_void_expression.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no_confusing_void_expression
22

33
import (
4+
"encoding/json"
45
"github.com/microsoft/typescript-go/shim/ast"
56
"github.com/microsoft/typescript-go/shim/checker"
67
"github.com/microsoft/typescript-go/shim/scanner"
@@ -58,17 +59,29 @@ func buildVoidExprWrapVoidMessage() rule.RuleMessage {
5859
}
5960

6061
type NoConfusingVoidExpressionOptions struct {
61-
IgnoreArrowShorthand bool
62-
IgnoreVoidOperator bool
63-
IgnoreVoidReturningFunctions bool
62+
IgnoreArrowShorthand bool `json:"ignoreArrowShorthand,omitempty"`
63+
IgnoreVoidOperator bool `json:"ignoreVoidOperator,omitempty"`
64+
IgnoreVoidReturningFunctions bool `json:"ignoreVoidReturningFunctions,omitempty"`
6465
}
6566

6667
var NoConfusingVoidExpressionRule = rule.CreateRule(rule.Rule{
6768
Name: "no-confusing-void-expression",
6869
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
6970
opts, ok := options.(NoConfusingVoidExpressionOptions)
71+
7072
if !ok {
73+
// try convert options to JSON and back to struct
7174
opts = NoConfusingVoidExpressionOptions{}
75+
// get first element of options
76+
options_array, _ := options.([]interface{})
77+
// if options_array has at least one element, try to unmarshal it
78+
if len(options_array) > 0 {
79+
optsJSON, err := json.Marshal(options_array[0])
80+
if err == nil {
81+
json.Unmarshal(optsJSON, &opts)
82+
}
83+
84+
}
7285
}
7386

7487
canFix := func(node *ast.Node) bool {

internal/utils/create_program.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ func CreateProgram(singleThreaded bool, fs vfs.FS, cwd string, tsconfigPath stri
4343

4444
diagnostics := program.GetSyntacticDiagnostics(context.Background(), nil)
4545
if len(diagnostics) != 0 {
46-
return nil, fmt.Errorf("found %v syntactic errors. Try running \"tsgo --noEmit\" first", len(diagnostics))
46+
// convert diagnostics to a string for better error reporting
47+
var diagnosticStrings []string
48+
for _, diagnostic := range diagnostics {
49+
diagnosticStrings = append(diagnosticStrings, diagnostic.Message(), diagnostic.File().Text())
50+
}
51+
return nil, fmt.Errorf("found %v syntactic errors. %v", len(diagnostics), diagnosticStrings)
4752
}
4853

4954
program.BindSourceFiles()

packages/rslint-test-tools/rstest.config.mts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ export default defineConfig({
44
testEnvironment: 'node',
55
globals: true,
66
include: [
7-
'./tests/typescript-eslint/rules/await-thenable.test.ts',
8-
'./tests/typescript-eslint/rules/no-array-delete.test.ts',
9-
'./tests/typescript-eslint/rules/no-for-in-array.test.ts',
107
'./tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts',
118
'./tests/typescript-eslint/rules/array-type.test.ts',
9+
'./tests/typescript-eslint/rules/await-thenable.test.ts',
10+
'./tests/typescript-eslint/rules/class-literal-property-style.test.ts',
11+
'./tests/typescript-eslint/rules/no-array-delete.test.ts',
12+
'./tests/typescript-eslint/rules/no-confusing-void-expression.test.ts',
1213
],
1314
});
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"compilerOptions": {
33
"strictNullChecks": true,
4-
"isolatedModules": true
4+
"isolatedModules": true,
5+
"jsx": "preserve"
56
},
6-
"include": ["src/**/*.ts"]
7-
}
7+
"include": [
8+
"src/**/*.ts"
9+
]
10+
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"compilerOptions": {
3-
"strictNullChecks": true
3+
"strictNullChecks": true,
4+
"jsx": "preserve"
45
},
5-
"include": ["src/virtual.ts"]
6-
}
6+
"include": [
7+
"src/virtual.ts"
8+
]
9+
}

0 commit comments

Comments
 (0)