Skip to content

Add TypeScript ESLint rules: dot-notation, explicit-member-accessibility, max-params, member-ordering, no-unnecessary-type-assertion #201

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
eadb04f
feat(rules): add new TypeScript ESLint rules implementation
ScriptedAlchemy Aug 7, 2025
ec62979
Add TypeScript ESLint rules: dot-notation, explicit-member-accessibil…
ScriptedAlchemy Aug 7, 2025
385113a
Update API and fix dot-notation rule implementation
ScriptedAlchemy Aug 7, 2025
d2fc809
feat: improve dot-notation rule implementation and add comprehensive …
ScriptedAlchemy Aug 8, 2025
609739c
feat: update dot-notation rule implementation and test snapshots
ScriptedAlchemy Aug 8, 2025
bc4ac1c
feat(dot-notation): improve template literal pattern matching and rul…
ScriptedAlchemy Aug 8, 2025
24b0bc1
feat(linter): add languageOptions support for TypeScript parser
ScriptedAlchemy Aug 8, 2025
7c86205
Update internal/rules/member_ordering/member_ordering.go
ScriptedAlchemy Aug 8, 2025
2729904
fix: improve Go code quality by addressing golangci-lint issues
ScriptedAlchemy Aug 8, 2025
d33a608
fix: apply go fmt formatting fixes
ScriptedAlchemy Aug 8, 2025
e90bebe
fix: remove unused functions to address golangci-lint warnings
ScriptedAlchemy Aug 8, 2025
62ca3e6
chore: update project files
ScriptedAlchemy Aug 8, 2025
c39fdec
fix: address remaining golangci-lint QF1003 and unconvert issues
ScriptedAlchemy Aug 8, 2025
0d8c6bf
fix: remove unused functions to resolve golangci-lint warnings
ScriptedAlchemy Aug 8, 2025
d86526e
fix: remove remaining unused functions in explicit_member_accessibili…
ScriptedAlchemy Aug 8, 2025
df2665c
fix: convert if-else to switch statement in member_ordering.go
ScriptedAlchemy Aug 8, 2025
5a0a457
fix: improve tagged switch to address QF1002 staticcheck warning
ScriptedAlchemy Aug 8, 2025
2fdf072
fix: add nolint directive for false positive staticcheck warning
ScriptedAlchemy Aug 8, 2025
c423078
Fix API to handle project as string or array - member ordering now wo…
ScriptedAlchemy Aug 8, 2025
558344a
Add debug logging to member-ordering rule to diagnose ordering issues
ScriptedAlchemy Aug 8, 2025
de4a098
fix: Add languageOptions.parserOptions.project support to Go rule tester
ScriptedAlchemy Aug 8, 2025
c3f360c
test: update snapshots for dot-notation and member-ordering
ScriptedAlchemy Aug 8, 2025
36b74aa
test: update snapshots; align dot-notation ranges and refine member-o…
ScriptedAlchemy Aug 8, 2025
4aa30c2
test(dot-notation): update invalid 12 snapshot start column to 4 to m…
ScriptedAlchemy Aug 8, 2025
dd7a11c
Merge remote-tracking branch 'origin/main' into rule-batch-3
ScriptedAlchemy Aug 8, 2025
b504ff2
feat(rules): refine dot-notation range ordering; re-enable constructo…
ScriptedAlchemy Aug 8, 2025
cf3c2db
chore(scripts): add sync-tse-rules.mjs to fetch missing typescript-es…
ScriptedAlchemy Aug 8, 2025
cad423e
fix(explicit-member-accessibility): report on node directly for corre…
ScriptedAlchemy Aug 8, 2025
47208db
fix: resolve CI linting issues
ScriptedAlchemy Aug 9, 2025
c18cc95
fix: remove unused function and fix empty branch
ScriptedAlchemy Aug 9, 2025
41d2136
fix: resolve spell check issues
ScriptedAlchemy Aug 9, 2025
a24653d
Delete .trae/TODO.md
ScriptedAlchemy Aug 9, 2025
0b611a6
Merge origin/main into rule-batch-3
ScriptedAlchemy Aug 12, 2025
16de55a
chore: update typescript-go submodule pointer
ScriptedAlchemy Aug 12, 2025
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
431 changes: 431 additions & 0 deletions .trae/documents/api_architecture.md

Large diffs are not rendered by default.

559 changes: 559 additions & 0 deletions .trae/documents/cli_commands_build_system.md

Large diffs are not rendered by default.

1,880 changes: 1,880 additions & 0 deletions .trae/documents/comprehensive_rslint_ast_parser_documentation.md

Large diffs are not rendered by default.

562 changes: 562 additions & 0 deletions .trae/documents/configuration_management.md

Large diffs are not rendered by default.

425 changes: 425 additions & 0 deletions .trae/documents/go_api_documentation.md

Large diffs are not rendered by default.

419 changes: 419 additions & 0 deletions .trae/documents/rule_registration_system.md

Large diffs are not rendered by default.

513 changes: 513 additions & 0 deletions .trae/documents/technical_architecture_document.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

This guide helps AI agents understand and work with the Rslint codebase effectively.

## Comprehensive Documentation Reference

**For detailed technical information**, refer to the comprehensive documentation in the `.trae/documents/` directory:

- **Go API Documentation** (`go_api_documentation.md`): Complete reference for all Go APIs, including CLI commands, core linting engine, TypeScript-Go integration, rule implementations, and internal utilities with detailed function signatures, usage examples, and architectural patterns.

- **AST & Parser Documentation** (`ast_parser_configuration_documentation.md`): Exhaustive coverage of AST nodes, parser implementation, configuration systems, TypeScript compiler integration, checker services, symbol resolution, type system, scanner/lexer, and complete technical architecture with type definitions and implementation details.

These documents provide 20x more detail than this guide, including:

- Complete function signatures and type definitions
- Detailed implementation specifics and algorithms
- Comprehensive code examples and usage patterns
- Architectural diagrams and system interactions
- Performance characteristics and optimization guidelines
- Threading models and memory management
- Integration patterns and best practices

## Core Concepts

Rslint is a TypeScript/JavaScript linter written in Go that implements TypeScript-ESLint rules. It uses the TypeScript compiler API through a Go shim and provides diagnostics via CLI and Language Server Protocol (LSP).
Expand Down
57 changes: 55 additions & 2 deletions cmd/rslint/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"
"sync"
Expand All @@ -20,6 +21,10 @@ import (
"github.com/web-infra-dev/rslint/internal/rules/array_type"
"github.com/web-infra-dev/rslint/internal/rules/await_thenable"
"github.com/web-infra-dev/rslint/internal/rules/class_literal_property_style"
"github.com/web-infra-dev/rslint/internal/rules/dot_notation"
"github.com/web-infra-dev/rslint/internal/rules/explicit_member_accessibility"
"github.com/web-infra-dev/rslint/internal/rules/max_params"
"github.com/web-infra-dev/rslint/internal/rules/member_ordering"
"github.com/web-infra-dev/rslint/internal/rules/no_array_delete"
"github.com/web-infra-dev/rslint/internal/rules/no_base_to_string"
"github.com/web-infra-dev/rslint/internal/rules/no_confusing_void_expression"
Expand Down Expand Up @@ -104,14 +109,54 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error)
rslintconfig.RegisterAllTypeScriptEslintPluginRules()

// Load rslint configuration and determine which tsconfig files to use
_, tsConfigs, configDirectory := rslintconfig.LoadConfigurationWithFallback(req.Config, currentDirectory, fs)
var tsConfigs []string
var configDirectory string

if req.LanguageOptions != nil && req.LanguageOptions.ParserOptions != nil && req.LanguageOptions.ParserOptions.Project != nil {
// Use project from languageOptions
configDirectory = currentDirectory

var projectPaths []string
switch project := req.LanguageOptions.ParserOptions.Project.(type) {
case string:
if project != "" {
projectPaths = []string{project}
}
case []interface{}:
for _, p := range project {
if str, ok := p.(string); ok && str != "" {
projectPaths = append(projectPaths, str)
}
}
}

if len(projectPaths) == 0 {
return nil, errors.New("no valid project paths found in languageOptions")
}

// Resolve and validate all project paths
for _, projectPath := range projectPaths {
resolvedPath := tspath.ResolvePath(currentDirectory, projectPath)
if !fs.FileExists(resolvedPath) {
return nil, fmt.Errorf("tsconfig file specified in languageOptions %q doesn't exist", resolvedPath)
}
tsConfigs = append(tsConfigs, resolvedPath)
}
} else {
// Use default configuration loading
_, tsConfigs, configDirectory = rslintconfig.LoadConfigurationWithFallback(req.Config, currentDirectory, fs)
}

// Create rules
var origin_rules = []rule.Rule{
adjacent_overload_signatures.AdjacentOverloadSignaturesRule,
array_type.ArrayTypeRule,
await_thenable.AwaitThenableRule,
class_literal_property_style.ClassLiteralPropertyStyleRule,
dot_notation.DotNotationRule,
explicit_member_accessibility.ExplicitMemberAccessibilityRule,
max_params.MaxParamsRule,
member_ordering.MemberOrderingRule,
no_array_delete.NoArrayDeleteRule,
no_base_to_string.NoBaseToStringRule,
no_confusing_void_expression.NoConfusingVoidExpressionRule,
Expand Down Expand Up @@ -168,7 +213,15 @@ func (h *IPCHandler) HandleLint(req api.LintRequest) (*api.LintResponse, error)
// filter rule based on request.RuleOptions
if len(req.RuleOptions) > 0 {
for _, r := range origin_rules {
if option, ok := req.RuleOptions[r.Name]; ok {
// Try both short name and full @typescript-eslint/ prefixed name
var option interface{}
var found bool
if option, found = req.RuleOptions[r.Name]; !found {
// Try with full @typescript-eslint/ prefix
option, found = req.RuleOptions["@typescript-eslint/"+r.Name]
}

if found {
rulesWithOptions = append(rulesWithOptions, RuleWithOption{
rule: r,
option: option,
Expand Down
16 changes: 14 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,27 @@ type HandshakeResponse struct {
OK bool `json:"ok"`
}

// LanguageOptions represents language-specific parser options
type LanguageOptions struct {
ParserOptions *ParserOptions `json:"parserOptions,omitempty"`
}

// ParserOptions represents TypeScript parser options
type ParserOptions struct {
Project interface{} `json:"project,omitempty"` // Can be string or []string
ProjectService bool `json:"projectService,omitempty"`
}

// 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"`
// 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
RuleOptions map[string]interface{} `json:"ruleOptions,omitempty"`
FileContents map[string]string `json:"fileContents,omitempty"` // Map of file paths to their contents for VFS
LanguageOptions *LanguageOptions `json:"languageOptions,omitempty"`
}

// LintResponse represents a lint response from Go to JS
Expand Down
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/web-infra-dev/rslint/internal/rules/array_type"
"github.com/web-infra-dev/rslint/internal/rules/await_thenable"
"github.com/web-infra-dev/rslint/internal/rules/class_literal_property_style"
"github.com/web-infra-dev/rslint/internal/rules/dot_notation"
"github.com/web-infra-dev/rslint/internal/rules/explicit_member_accessibility"
"github.com/web-infra-dev/rslint/internal/rules/max_params"
"github.com/web-infra-dev/rslint/internal/rules/member_ordering"
"github.com/web-infra-dev/rslint/internal/rules/no_array_delete"
"github.com/web-infra-dev/rslint/internal/rules/no_base_to_string"
"github.com/web-infra-dev/rslint/internal/rules/no_confusing_void_expression"
Expand Down Expand Up @@ -272,6 +276,10 @@ func RegisterAllTypeScriptEslintPluginRules() {
GlobalRuleRegistry.Register("@typescript-eslint/array-type", array_type.ArrayTypeRule)
GlobalRuleRegistry.Register("@typescript-eslint/await-thenable", await_thenable.AwaitThenableRule)
GlobalRuleRegistry.Register("@typescript-eslint/class-literal-property-style", class_literal_property_style.ClassLiteralPropertyStyleRule)
GlobalRuleRegistry.Register("@typescript-eslint/dot-notation", dot_notation.DotNotationRule)
GlobalRuleRegistry.Register("@typescript-eslint/explicit-member-accessibility", explicit_member_accessibility.ExplicitMemberAccessibilityRule)
GlobalRuleRegistry.Register("@typescript-eslint/max-params", max_params.MaxParamsRule)
GlobalRuleRegistry.Register("@typescript-eslint/member-ordering", member_ordering.MemberOrderingRule)
GlobalRuleRegistry.Register("@typescript-eslint/no-array-delete", no_array_delete.NoArrayDeleteRule)
GlobalRuleRegistry.Register("@typescript-eslint/no-base-to-string", no_base_to_string.NoBaseToStringRule)
GlobalRuleRegistry.Register("@typescript-eslint/no-confusing-void-expression", no_confusing_void_expression.NoConfusingVoidExpressionRule)
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
Loading