-
-
Notifications
You must be signed in to change notification settings - Fork 0
Enable full test for class-methods-use-this rule #154
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
Conversation
## Summary
- Uncommented the full test file for class-methods-use-this rule in rstest.config.mts
- Extended implementation to support `ignoreClassesThatImplementAnInterface` option (boolean or "public-fields")
- Extended implementation to support `ignoreOverrideMethods` option
- All tests now pass successfully
## Changes
### Test Configuration (rstest.config.mts:38)
- Uncommented the line enabling the class-methods-use-this full test file
### Implementation (class_methods_use_this.go)
Extended the rule to support advanced TypeScript-ESLint options:
1. **ignoreClassesThatImplementAnInterface**:
- When `true`: ignores all members of classes that implement interfaces
- When `"public-fields"`: only ignores public members, still checks private/protected members
- When `false`: checks all members (default behavior)
2. **ignoreOverrideMethods**:
- When `true`: ignores methods with the `override` modifier
- When `false`: checks override methods (default behavior)
3. **Implementation details**:
- Added helper functions to check if a class implements an interface
- Added helper to check if a member has the override modifier
- Added logic to determine whether to ignore members based on:
- Class interface implementation status
- Member visibility (public/private/protected)
- Override modifier presence
- Applied these checks to both methods and property initializers
### Test Snapshots
- Created snapshot file with 40 test cases covering:
- Basic method detection
- Private/protected methods
- Getter/setter detection
- Classes implementing interfaces
- Override methods
- Property initializers
- Combination of options
## Context
This PR is a follow-up to #152 and #153, which enabled the core test. This PR enables the full test suite with advanced TypeScript-specific features.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
🤖 This pull request has been linked to DevBird Task #1536 View the task details and manage the automated development workflow in DevBird. Learn more about DevBird here or the announcement blog post here. |
📋 DevBird Task PromptEnable the test for the complete ObjectiveUncomment the test file Documentation & Resources
Implementation Steps
Critical RequirementIf CI fails, ensure complete implementation of class-methods-use-this:
Success Criteria
This comment was automatically added by DevBird. You can disable this feature in DevBird Settings. |
Code Review - PR #154: Enable full test for class-methods-use-this ruleSummaryThis PR successfully extends the ✅ Strengths
🔍 Code Quality Issues1. Redundant Code Duplication (Lines 141-161)The private name checking logic is duplicated across 4 different node types. Consider extracting this into a helper function: // Helper to check if a member has a private name
isPrivateName := func(node *ast.Node) bool {
var name *ast.Node
switch node.Kind {
case ast.KindMethodDeclaration:
if method := node.AsMethodDeclaration(); method != nil {
name = method.Name()
}
case ast.KindPropertyDeclaration:
if prop := node.AsPropertyDeclaration(); prop != nil {
name = prop.Name()
}
case ast.KindGetAccessor:
if accessor := node.AsGetAccessorDeclaration(); accessor != nil {
name = accessor.Name()
}
case ast.KindSetAccessor:
if accessor := node.AsSetAccessorDeclaration(); accessor != nil {
name = accessor.Name()
}
default:
return false
}
if name != nil {
_, nameType := utils.GetNameFromMember(ctx.SourceFile, name)
return nameType == utils.MemberNameTypePrivate
}
return false
}Location: 2. Redundant Function Call (Lines 85-95)The // Refactor to reuse getParentClass
isInClass := func(node *ast.Node) bool {
return getParentClass(node) != nil
}Location: 3. Nil Check Redundancy (Line 119)The nil check for // Current (line 119)
if opts.IgnoreClassesThatImplementAnInterface == nil || opts.IgnoreClassesThatImplementAnInterface == false {
return false
}
// Improved - handle nil and false separately for clarity
if opts.IgnoreClassesThatImplementAnInterface == nil {
return false
}
if boolVal, ok := opts.IgnoreClassesThatImplementAnInterface.(bool); ok && !boolVal {
return false
}Location: 🐛 Potential Bugs1. Edge Case: Multiple Interface ImplementationThe Location: 2. Accessor Auto-Accessors Edge Case (Lines 151-161)The code checks for getters/setters, but TypeScript also has "accessor" auto-accessors. Verify the test cases cover Location: Test coverage verified ✓ ⚡ Performance Considerations1. Repeated Parent Traversal (Lines 86-95, 123)Every call to Impact: Minor - only called once per method, but worth noting. 2. Heritage Clause Iteration (Lines 108-113)The loop could short-circuit earlier: for _, clauseNode := range heritageClauses.Nodes {
clause := clauseNode.AsHeritageClause()
if clause != nil && clause.Token == ast.KindImplementsKeyword {
return true // ✓ Already does this - good!
}
}Location: Already optimized ✓ 🔒 Security ConcernsNo security issues identified. The code:
🧪 Test CoverageExcellent coverage with 40 test cases including:
Suggestion: Consider adding test cases for:
📝 Best Practices & Style1. Consistent Error Messages ✓Error messages properly distinguish between regular and private members. Good! 2. Option Parsing ✓Follows the same pattern as 3. Comment QualityComments are clear and helpful. Consider adding a package-level comment explaining the rule's purpose. 🎯 RecommendationsPriority 1 (Should fix before merge):
Priority 2 (Nice to have):
Priority 3 (Future optimization):
✨ Overall AssessmentVerdict: ✅ Approve with minor suggestions This is a solid implementation that:
The identified issues are mostly about code quality and maintainability rather than correctness. The rule works as intended, and the test coverage gives confidence in its behavior. Great work on this incremental improvement to the linting rule! 🎉 Review generated by Claude Code - kdybot/rslint PR #154 |
## Summary - Uncommented the full test file for class-methods-use-this rule in `rstest.config.mts` - Extended implementation to support `ignoreClassesThatImplementAnInterface` option (boolean or "public-fields") - Extended implementation to support `ignoreOverrideMethods` option - All tests now pass successfully ## Context This PR is a follow-up to #152 and #153, which enabled the core test. This PR enables the full test suite with advanced TypeScript-specific features. ## Changes ### Test Configuration (rstest.config.mts:38) - Uncommented the line enabling the class-methods-use-this full test file ### Implementation (internal/plugins/typescript/rules/class_methods_use_this/class_methods_use_this.go) Extended the rule to support advanced TypeScript-ESLint options: 1. **ignoreClassesThatImplementAnInterface**: - When `true`: ignores all members of classes that implement interfaces - When `"public-fields"`: only ignores public members, still checks private/protected members - When `false`: checks all members (default behavior) 2. **ignoreOverrideMethods**: - When `true`: ignores methods with the `override` modifier - When `false`: checks override methods (default behavior) 3. **Implementation details**: - Added helper functions to check if a class implements an interface - Added helper to check if a member has the override modifier - Added logic to determine whether to ignore members based on: - Class interface implementation status - Member visibility (public/private/protected) - Override modifier presence - Applied these checks to both methods and property initializers ### Test Snapshots - Created snapshot file with 40 test cases covering: - Basic method detection - Private/protected methods - Getter/setter detection - Classes implementing interfaces - Override methods - Property initializers - Combination of options ## Test Results All tests pass successfully: - Valid test cases: ✓ (3.53s) - Invalid test cases: ✓ (4.06s) - Total: 2 passed ## TypeScript-ESLint Reference The implementation follows the behavior of the TypeScript-ESLint class-methods-use-this rule: https://typescript-eslint.io/rules/class-methods-use-this/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit uncomments the test file for the consistent-generic-constructors rule in rstest.config.mts. All tests pass successfully. The consistent-generic-constructors rule enforces consistent placement of type arguments in constructor calls: - 'type-annotation' style: const x: Foo<string> = new Foo() - 'constructor' style (default): const x = new Foo<string>() Test results: - All 75 test cases pass (50 valid, 25 invalid) - Go implementation already supports all features - Follows pattern from #154 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
## Summary - Uncommented the test file for consistent-generic-constructors rule in `rstest.config.mts` - All tests now pass successfully ## Context This PR is a follow-up to #154, which enabled the test for class-methods-use-this rule. This PR enables the test suite for consistent-generic-constructors. ## Changes ### Test Configuration (rstest.config.mts:39) - Uncommented the line enabling the consistent-generic-constructors test file ### Implementation Status The Go implementation at `internal/plugins/typescript/rules/consistent_generic_constructors/` already supports all required features: 1. **Default 'constructor' style**: Enforces type arguments on constructor calls - Example: `const a = new Foo<string>();` 2. **'type-annotation' style option**: Enforces type arguments on type annotations - Example: `const a: Foo<string> = new Foo();` 3. **Comprehensive coverage**: - Variable declarations - Property declarations (including accessor properties) - Function/method parameters - Destructuring patterns - Default parameter values ## Test Results All tests pass successfully: - 50 valid test cases: ✓ - 25 invalid test cases: ✓ - Total: 75 test cases passed ## TypeScript-ESLint Reference The implementation follows the behavior of the TypeScript-ESLint consistent-generic-constructors rule: https://typescript-eslint.io/rules/consistent-generic-constructors/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
## Summary - Uncommented the full test file for class-methods-use-this rule in `rstest.config.mts` - Extended implementation to support `ignoreClassesThatImplementAnInterface` option (boolean or "public-fields") - Extended implementation to support `ignoreOverrideMethods` option - All tests now pass successfully ## Context This PR is a follow-up to #152 and #153, which enabled the core test. This PR enables the full test suite with advanced TypeScript-specific features. ## Changes ### Test Configuration (rstest.config.mts:38) - Uncommented the line enabling the class-methods-use-this full test file ### Implementation (internal/plugins/typescript/rules/class_methods_use_this/class_methods_use_this.go) Extended the rule to support advanced TypeScript-ESLint options: 1. **ignoreClassesThatImplementAnInterface**: - When `true`: ignores all members of classes that implement interfaces - When `"public-fields"`: only ignores public members, still checks private/protected members - When `false`: checks all members (default behavior) 2. **ignoreOverrideMethods**: - When `true`: ignores methods with the `override` modifier - When `false`: checks override methods (default behavior) 3. **Implementation details**: - Added helper functions to check if a class implements an interface - Added helper to check if a member has the override modifier - Added logic to determine whether to ignore members based on: - Class interface implementation status - Member visibility (public/private/protected) - Override modifier presence - Applied these checks to both methods and property initializers ### Test Snapshots - Created snapshot file with 40 test cases covering: - Basic method detection - Private/protected methods - Getter/setter detection - Classes implementing interfaces - Override methods - Property initializers - Combination of options ## Test Results All tests pass successfully: - Valid test cases: ✓ (3.53s) - Invalid test cases: ✓ (4.06s) - Total: 2 passed ## TypeScript-ESLint Reference The implementation follows the behavior of the TypeScript-ESLint class-methods-use-this rule: https://typescript-eslint.io/rules/class-methods-use-this/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
## Summary - Uncommented the test file for consistent-generic-constructors rule in `rstest.config.mts` - All tests now pass successfully ## Context This PR is a follow-up to #154, which enabled the test for class-methods-use-this rule. This PR enables the test suite for consistent-generic-constructors. ## Changes ### Test Configuration (rstest.config.mts:39) - Uncommented the line enabling the consistent-generic-constructors test file ### Implementation Status The Go implementation at `internal/plugins/typescript/rules/consistent_generic_constructors/` already supports all required features: 1. **Default 'constructor' style**: Enforces type arguments on constructor calls - Example: `const a = new Foo<string>();` 2. **'type-annotation' style option**: Enforces type arguments on type annotations - Example: `const a: Foo<string> = new Foo();` 3. **Comprehensive coverage**: - Variable declarations - Property declarations (including accessor properties) - Function/method parameters - Destructuring patterns - Default parameter values ## Test Results All tests pass successfully: - 50 valid test cases: ✓ - 25 invalid test cases: ✓ - Total: 75 test cases passed ## TypeScript-ESLint Reference The implementation follows the behavior of the TypeScript-ESLint consistent-generic-constructors rule: https://typescript-eslint.io/rules/consistent-generic-constructors/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
## Summary - Uncommented the full test file for class-methods-use-this rule in `rstest.config.mts` - Extended implementation to support `ignoreClassesThatImplementAnInterface` option (boolean or "public-fields") - Extended implementation to support `ignoreOverrideMethods` option - All tests now pass successfully ## Context This PR is a follow-up to #152 and #153, which enabled the core test. This PR enables the full test suite with advanced TypeScript-specific features. ## Changes ### Test Configuration (rstest.config.mts:38) - Uncommented the line enabling the class-methods-use-this full test file ### Implementation (internal/plugins/typescript/rules/class_methods_use_this/class_methods_use_this.go) Extended the rule to support advanced TypeScript-ESLint options: 1. **ignoreClassesThatImplementAnInterface**: - When `true`: ignores all members of classes that implement interfaces - When `"public-fields"`: only ignores public members, still checks private/protected members - When `false`: checks all members (default behavior) 2. **ignoreOverrideMethods**: - When `true`: ignores methods with the `override` modifier - When `false`: checks override methods (default behavior) 3. **Implementation details**: - Added helper functions to check if a class implements an interface - Added helper to check if a member has the override modifier - Added logic to determine whether to ignore members based on: - Class interface implementation status - Member visibility (public/private/protected) - Override modifier presence - Applied these checks to both methods and property initializers ### Test Snapshots - Created snapshot file with 40 test cases covering: - Basic method detection - Private/protected methods - Getter/setter detection - Classes implementing interfaces - Override methods - Property initializers - Combination of options ## Test Results All tests pass successfully: - Valid test cases: ✓ (3.53s) - Invalid test cases: ✓ (4.06s) - Total: 2 passed ## TypeScript-ESLint Reference The implementation follows the behavior of the TypeScript-ESLint class-methods-use-this rule: https://typescript-eslint.io/rules/class-methods-use-this/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
## Summary - Uncommented the test file for consistent-generic-constructors rule in `rstest.config.mts` - All tests now pass successfully ## Context This PR is a follow-up to #154, which enabled the test for class-methods-use-this rule. This PR enables the test suite for consistent-generic-constructors. ## Changes ### Test Configuration (rstest.config.mts:39) - Uncommented the line enabling the consistent-generic-constructors test file ### Implementation Status The Go implementation at `internal/plugins/typescript/rules/consistent_generic_constructors/` already supports all required features: 1. **Default 'constructor' style**: Enforces type arguments on constructor calls - Example: `const a = new Foo<string>();` 2. **'type-annotation' style option**: Enforces type arguments on type annotations - Example: `const a: Foo<string> = new Foo();` 3. **Comprehensive coverage**: - Variable declarations - Property declarations (including accessor properties) - Function/method parameters - Destructuring patterns - Default parameter values ## Test Results All tests pass successfully: - 50 valid test cases: ✓ - 25 invalid test cases: ✓ - Total: 75 test cases passed ## TypeScript-ESLint Reference The implementation follows the behavior of the TypeScript-ESLint consistent-generic-constructors rule: https://typescript-eslint.io/rules/consistent-generic-constructors/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
Summary
rstest.config.mtsignoreClassesThatImplementAnInterfaceoption (boolean or "public-fields")ignoreOverrideMethodsoptionContext
This PR is a follow-up to #152 and #153, which enabled the core test. This PR enables the full test suite with advanced TypeScript-specific features.
Changes
Test Configuration (rstest.config.mts:38)
Implementation (internal/plugins/typescript/rules/class_methods_use_this/class_methods_use_this.go)
Extended the rule to support advanced TypeScript-ESLint options:
ignoreClassesThatImplementAnInterface:
true: ignores all members of classes that implement interfaces"public-fields": only ignores public members, still checks private/protected membersfalse: checks all members (default behavior)ignoreOverrideMethods:
true: ignores methods with theoverridemodifierfalse: checks override methods (default behavior)Implementation details:
Test Snapshots
Test Results
All tests pass successfully:
TypeScript-ESLint Reference
The implementation follows the behavior of the TypeScript-ESLint class-methods-use-this rule:
https://typescript-eslint.io/rules/class-methods-use-this/
🤖 Generated with Claude Code