Skip to content

Fix CI build and test failures: initialize git submodules and resolve test issues #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: rule-batch-3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .trae/TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# TODO:

- [ ] 12: Investigate test infrastructure code to understand how languageOptions are handled (priority: High)
- [ ] 13: Find where parserOptions.project settings should be passed to the Go linter (priority: High)
- [ ] 14: Identify the gap in the test infrastructure that prevents proper option propagation (priority: High)
- [ ] 15: Fix the infrastructure to properly pass languageOptions.parserOptions.project to linter (priority: High)
- [ ] 16: Test the fix with dot-notation rule that depends on noPropertyAccessFromIndexSignature (priority: Medium)
- [x] 12: Investigate test infrastructure code to understand how languageOptions are handled (priority: High)
- [x] 13: Find where parserOptions.project settings should be passed to the Go linter (priority: High)
- [x] 14: Identify the gap in the test infrastructure that prevents proper option propagation (priority: High)
- [x] 15: Fix the Go rule tester to support languageOptions.parserOptions.project from test cases (priority: High)
- [x] 16: Run full test suite with pnpm test (priority: High)
- [x] 17: Run Go tests with go test ./... (core tests passing, rule tests have timeout issues) (priority: High)
- [x] 18: Build project with go build ./... and pnpm build (priority: Medium)
- [ ] 19: Provide detailed report on test results and any remaining issues (**IN PROGRESS**) (priority: Medium)
2 changes: 1 addition & 1 deletion cmd/rslint/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error)
// Load rslint configuration and determine which tsconfig files to use
var tsConfigs []string
var configDirectory string

if req.LanguageOptions != nil && req.LanguageOptions.ParserOptions != nil && req.LanguageOptions.ParserOptions.Project != "" {
// Use project from languageOptions
configDirectory = currentDirectory
Expand Down
8 changes: 4 additions & 4 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ type ParserOptions struct {

// LintRequest represents a lint request from JS to Go
type LintRequest struct {
Files []string `json:"files,omitempty"`
Config string `json:"config,omitempty"` // Path to rslint.json config file
Format string `json:"format,omitempty"`
WorkingDirectory string `json:"workingDirectory,omitempty"`
Files []string `json:"files,omitempty"`
Config string `json:"config,omitempty"` // Path to rslint.json config file
Format string `json:"format,omitempty"`
WorkingDirectory string `json:"workingDirectory,omitempty"`
// Supports both string level and array [level, options] format
RuleOptions map[string]interface{} `json:"ruleOptions,omitempty"`
FileContents map[string]string `json:"fileContents,omitempty"` // Map of file paths to their contents for VFS
Expand Down
51 changes: 33 additions & 18 deletions internal/rule_tester/rule_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ import (
"gotest.tools/v3/assert"
)

type LanguageOptions struct {
ParserOptions *ParserOptions `json:"parserOptions,omitempty"`
}

type ParserOptions struct {
Project string `json:"project,omitempty"`
ProjectService bool `json:"projectService,omitempty"`
}

type ValidTestCase struct {
Code string
Only bool
Skip bool
Options any
TSConfig string
Tsx bool
Code string
Only bool
Skip bool
Options any
TSConfig string
Tsx bool
LanguageOptions *LanguageOptions
}

type InvalidTestCaseError struct {
Expand All @@ -40,14 +50,15 @@ type InvalidTestCaseSuggestion struct {
}

type InvalidTestCase struct {
Code string
Only bool
Skip bool
Output []string
Errors []InvalidTestCaseError
TSConfig string
Options any
Tsx bool
Code string
Only bool
Skip bool
Output []string
Errors []InvalidTestCaseError
TSConfig string
Options any
Tsx bool
LanguageOptions *LanguageOptions
}

func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Rule, validTestCases []ValidTestCase, invalidTestCases []InvalidTestCase) {
Expand All @@ -56,7 +67,7 @@ func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Ru
onlyMode := slices.ContainsFunc(validTestCases, func(c ValidTestCase) bool { return c.Only }) ||
slices.ContainsFunc(invalidTestCases, func(c InvalidTestCase) bool { return c.Only })

runLinter := func(t *testing.T, code string, options any, tsconfigPathOverride string, tsx bool) []rule.RuleDiagnostic {
runLinter := func(t *testing.T, code string, options any, tsconfigPathOverride string, tsx bool, languageOptions *LanguageOptions) []rule.RuleDiagnostic {
var diagnosticsMu sync.Mutex
diagnostics := make([]rule.RuleDiagnostic, 0, 3)

Expand All @@ -72,6 +83,10 @@ func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Ru
if tsconfigPathOverride != "" {
tsconfigPath = tsconfigPathOverride
}
// Override with languageOptions.parserOptions.project if provided
if languageOptions != nil && languageOptions.ParserOptions != nil && languageOptions.ParserOptions.Project != "" {
tsconfigPath = tspath.ResolvePath(rootDir, languageOptions.ParserOptions.Project)
}

program, err := utils.CreateProgram(true, fs, rootDir, tsconfigPath, host)
assert.NilError(t, err, "couldn't create program. code: "+code)
Expand All @@ -86,7 +101,7 @@ func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Ru
func(sourceFile *ast.SourceFile) []linter.ConfiguredRule {
return []linter.ConfiguredRule{
{
Name: "test",
Name: r.Name,
Severity: rule.SeverityError,
Run: func(ctx rule.RuleContext) rule.RuleListeners {
return r.Run(ctx, options)
Expand Down Expand Up @@ -114,7 +129,7 @@ func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Ru
t.SkipNow()
}

diagnostics := runLinter(t, testCase.Code, testCase.Options, testCase.TSConfig, testCase.Tsx)
diagnostics := runLinter(t, testCase.Code, testCase.Options, testCase.TSConfig, testCase.Tsx, testCase.LanguageOptions)
if len(diagnostics) != 0 {
// TODO: pretty errors
t.Errorf("Expected valid test case not to contain errors. Code:\n%v", testCase.Code)
Expand All @@ -139,7 +154,7 @@ func RunRuleTester(rootDir string, tsconfigPath string, t *testing.T, r *rule.Ru
code := testCase.Code

for i := range 10 {
diagnostics := runLinter(t, code, testCase.Options, testCase.TSConfig, testCase.Tsx)
diagnostics := runLinter(t, code, testCase.Options, testCase.TSConfig, testCase.Tsx, testCase.LanguageOptions)
if i == 0 {
initialDiagnostics = diagnostics
}
Expand Down
31 changes: 0 additions & 31 deletions internal/rules/dot_notation/dot_notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,6 @@ func hasIndexSignature(ctx rule.RuleContext, objectType *checker.Type) bool {
return numberIndexType != nil
}

// matchesIndexSignaturePattern checks if a property name matches index signature patterns
// For now, we'll use a simple heuristic: if the property is not explicitly declared
// but the type has index signatures, we allow bracket notation
func matchesIndexSignaturePattern(ctx rule.RuleContext, objectType *checker.Type, propertyName string) bool {
if objectType == nil {
return false
}

// Simple heuristic: if we have index signatures and the property is not explicitly declared,
// allow bracket notation. This handles cases like template literal types.
if hasIndexSignature(ctx, objectType) {
propSymbol := ctx.TypeChecker.GetPropertyOfType(objectType, propertyName)
return propSymbol == nil
}

return false
}

// matchesTemplateLiteralPattern checks if a property name matches template literal patterns
// This is a heuristic to handle cases like `key_${string}` where `key_baz` should be allowed
Expand Down Expand Up @@ -474,17 +457,3 @@ func getKeywordText(node *ast.Node) string {
}
}

// Message builders
func buildUseDotMessage(key string) rule.RuleMessage {
return rule.RuleMessage{
Id: "useDot",
Description: fmt.Sprintf("[%s] is better written in dot notation.", key),
}
}

func buildUseBracketsMessage(key string) rule.RuleMessage {
return rule.RuleMessage{
Id: "useBrackets",
Description: fmt.Sprintf(".%s is a syntax error.", key),
}
}
Loading
Loading