-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Implement TypeScript-ESLint no-restricted-types rule #212
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
base: main
Are you sure you want to change the base?
Conversation
Implement the TypeScript-ESLint `no-restricted-types` rule for rslint.
**Objective**: Create a complete implementation that disallows certain types based on configuration.
**Implementation Details**:
- Full implementation in Go at `internal/plugins/typescript/rules/no_restricted_types/no_restricted_types.go`
- Supports configurable type restrictions with custom messages
- Supports auto-fix suggestions via `fixWith` configuration
- Handles simple types (string, number, boolean, etc.)
- Handles complex types (qualified names like `NS.Type`, generics like `Type<T>`, empty tuples `[]`, empty objects `{}`)
- All original test cases from TypeScript-ESLint repository ported
- Test enabled in `packages/rslint-test-tools/rstest.config.mts`
**Features**:
- Restrict types by name with boolean `true` for default message
- Restrict types with custom string messages
- Restrict types with object configuration containing `message` and `fixWith` fields
- Support for namespace-qualified types (e.g., `NS.Banned`)
- Support for generic types (e.g., `Banned<any>`, `Banned<A,B>`)
- Normalization of type names (whitespace trimming)
**Testing**:
- All test cases from the original TypeScript-ESLint repository included
- Test file location: `packages/rslint-test-tools/tests/typescript-eslint/rules/no-restricted-types.test.ts`
🤖 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 #1598 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 PromptImplement the TypeScript-ESLint Objective: Create a complete implementation that disallows certain types. Documentation & Resources:
Implementation Requirements:
Testing Requirements:
Success Criteria:
This comment was automatically added by DevBird. You can disable this feature in DevBird Settings. |
Code Review: TypeScript-ESLint no-restricted-types Rule ImplementationThank you for implementing this rule! I've conducted a thorough review of the code quality, architecture, testing, and integration. Overall, this is a well-implemented feature that follows the codebase conventions closely. ✅ StrengthsCode Quality & Best Practices
Robust Options Parsing
Comprehensive Test Coverage (35 test cases)
Proper Integration
🔍 Areas for Improvement1. Generic Type Matching Logic (Potential Edge Case)Location: no_restricted_types.go:154-165 The code generates "Banned<A,B>" (no space) but test line 604 expects it to match config 'Banned<A, B>' (with space). Action needed: Please confirm the Banned<A,B> test (line 604) actually passes. 2. Message Formatting (Minor)Location: no_restricted_types.go:116 When customMessage is empty, the message ends with a period and nothing else. When customMessage has content, there's no space between the period and the custom message. 3. Missing Documentation (Minor)The rule implementation file lacks a package-level comment explaining what the rule does. Security & Performance✅ Security: No concerns identified. Input validation is implicit through Go's type system. ✅ Performance: Looks good with O(1) lookup, early returns, and efficient AST traversal (only 3 node kinds). Test Quality: 9.5/10Comprehensive coverage with good edge cases. Minor gap: No tests for null/false config values that allow types. 📋 Final Checklist
🎯 Recommendation: APPROVE with minor suggestionsThis is a solid implementation that follows the codebase patterns well. The code is production-ready. Action items:
Great work overall! The implementation is clean, well-tested, and integrates properly with the existing codebase. |
Fixed 5 compilation errors in the no-restricted-types rule implementation: 1. Changed `AsTupleType()` to `AsTupleTypeNode()` - correct method name 2. Fixed tuple element check: `tupleType.Elements.Nodes` instead of direct access 3. Fixed type literal member check: `typeLiteral.Members.Nodes` instead of direct access 4. Removed `Data` field from `RuleMessage` struct - field doesn't exist 5. Fixed TypeArguments iteration: `typeRef.TypeArguments.Nodes` instead of direct iteration These changes align with the TypeScript-Go AST API patterns used throughout the codebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Code Review: TypeScript-ESLint no-restricted-types Rule ImplementationSummaryThis PR implements the ✅ Strengths
🔍 Issues & Concerns1. Critical: Inconsistent Qualified Name HandlingLocation: The
Impact: This is actually correct for Recommendation: Add a comment explaining why qualified names are handled differently from 2. Potential Bug: Message Formatting IssueLocation: When
Expected:
3. Code Quality: Missing Constant for Message IDThe string 4. Inconsistency: Different Message Format from ban_types
This means the same configuration will produce different messages in the two rules. 🎯 Performance Considerations
🔒 Security ConsiderationsNo security concerns identified:
✅ Test CoverageThe PR description indicates all test cases from TypeScript-ESLint are ported, which is excellent. 📝 Recommendations SummaryMust Fix
Should Fix
Nice to Have
Overall AssessmentThis is a solid implementation that demonstrates good understanding of the codebase patterns. The main issue is the message formatting bug that should be addressed before merging. Otherwise, the code is production-ready with comprehensive test coverage. Rating: 7.5/10 (would be 9/10 after fixing the message spacing issue) 🤖 Generated with Claude Code |
Summary
Implements the TypeScript-ESLint
no-restricted-typesrule for rslint, which disallows certain types based on configuration.Implementation Details
Rule Implementation
internal/plugins/typescript/rules/no_restricted_types/no_restricted_types.goFeatures
✅ Restrict types with boolean
truefor default message✅ Restrict types with custom string messages
✅ Restrict types with object configuration (
messageandfixWithfields)✅ Support for namespace-qualified types (e.g.,
NS.Banned)✅ Support for generic types (e.g.,
Banned<any>,Banned<A,B>)✅ Support for empty tuples
[]and empty objects{}✅ Normalization of type names (whitespace trimming)
Testing
packages/rslint-test-tools/tests/typescript-eslint/rules/no-restricted-types.test.tspackages/rslint-test-tools/rstest.config.mtsChanges Made
internal/config/config.goDocumentation & References
Example Configuration
{ "@typescript-eslint/no-restricted-types": [ "error", { "types": { "String": { "message": "Use string instead", "fixWith": "string" }, "{}": { "message": "Use object instead", "fixWith": "object" } } } ] }Testing
The implementation includes all original test cases from the TypeScript-ESLint repository, covering:
🤖 Generated with Claude Code