Skip to content

Conversation

@delino
Copy link

@delino delino bot commented Nov 5, 2025

Summary

  • Enables the TypeScript-ESLint ban-tslint-comment rule test by adding it to the test configuration
  • The test file already exists at packages/rslint-test-tools/tests/typescript-eslint/rules/ban-tslint-comment.test.ts
  • Added the test path to the include array in packages/rslint-test-tools/rstest.config.mts

Test Details

The test verifies detection and removal of TSLint comment directives:

  • tslint:disable
  • tslint:enable
  • tslint:disable-line
  • tslint:disable-next-line

Notes

  • The existing test suite has pre-existing module resolution failures (Cannot find module '@typescript-eslint/rule-tester') that affect all TypeScript-ESLint rule tests
  • These failures appear to be unrelated to this change and need to be addressed separately
  • The test file structure follows the same pattern as other enabled tests

Reference

🤖 Generated with Claude Code

Add './tests/typescript-eslint/rules/ban-tslint-comment.test.ts' to the
include array in rstest.config.mts to enable testing of the
TypeScript-ESLint ban-tslint-comment rule.

The test file already exists and contains test cases for detecting and
removing tslint comment directives (tslint:disable, tslint:enable, etc.)

Note: Tests have pre-existing module resolution failures that need to be
addressed separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Owner

kdy1 commented Nov 5, 2025

🤖 This pull request has been linked to DevBird Task #1233

View the task details and manage the automated development workflow in DevBird.

Learn more about DevBird here or the announcement blog post here.

Copy link
Owner

kdy1 commented Nov 5, 2025

📋 DevBird Task Prompt

Enable the TypeScript-ESLint rule test for ban-tslint-comment by adding it to the test configuration.

Objective: Add './tests/typescript-eslint/rules/ban-tslint-comment.test.ts' to the include array in packages/rslint-test-tools/rstest.config.mts

Steps:

  1. Edit packages/rslint-test-tools/rstest.config.mts
  2. Add './tests/typescript-eslint/rules/ban-tslint-comment.test.ts' to the include array
  3. Run the tests and fix any failures in the implementation
  4. Ensure all tests pass

Reference Documentation:

Success Criteria:

  • Test enabled and passing

This comment was automatically added by DevBird. You can disable this feature in DevBird Settings.

@claude
Copy link

claude bot commented Nov 5, 2025

PR Review - Enable ban-tslint-comment test

Summary

This PR enables the ban-tslint-comment rule test by adding it to the test configuration.

Code Quality ✅

Strengths:

  • The change is minimal and focused - adds exactly one line to enable the test
  • Alphabetical ordering is correctly maintained in the include array
  • The test file already exists and follows the same pattern as other TypeScript-ESLint rule tests
  • The PR description is thorough and explains the change well

Observations:

  • The test file follows the expected pattern
  • Compared to other test files like array-type.test.ts and await-thenable.test.ts, the ban-tslint-comment test has a simpler structure without custom parser configuration

Potential Issues ⚠️

  1. Missing Rule Import: The test file references a rule name but doesn't import the actual rule implementation. Is it auto-loaded by the test framework?

  2. Test Configuration: The test uses a basic RuleTester without special configuration. Does the ban-tslint-comment rule require TypeScript type information, or is it purely syntactic?

Performance Considerations ✅

  • No performance concerns - this is a configuration change only
  • The change adds one more test file to the test suite (1 out of 155 total test files)

Security Concerns ✅

  • No security concerns identified
  • This is a test configuration change with no production code impact

Test Coverage ✅

Strengths:

  • The test file includes comprehensive coverage:
    • 5 valid test cases
    • 8 invalid test cases with expected errors and outputs
    • Tests cover all TSLint comment directives
    • Tests include edge cases like inline comments and multi-line scenarios

Recommendations

  1. Verify Pre-existing Failures: The PR description mentions pre-existing module resolution failures. Can you confirm these failures exist in the main branch? Should this be tracked as a separate issue?

  2. Run Tests: Before merging, ensure that pnpm test -- ban-tslint-comment passes (or fails with only the pre-existing issues mentioned)

  3. Consider Adding Documentation: If this is part of a larger effort to enable more TypeScript-ESLint tests, it might be helpful to track progress.

Conclusion

This is a clean, well-documented change that follows the existing patterns in the codebase. The test file itself appears comprehensive and properly structured.

Recommendation: APPROVE ✅ (pending verification that the test runs as expected with the known pre-existing issues)


Review generated with Claude Code

Add implementation for the @typescript-eslint/ban-tslint-comment rule
that detects and reports tslint directive comments (tslint:disable,
tslint:enable, tslint:disable-next-line, and tslint:disable-line).

This fixes the failing test that was enabled in the PR but had no
corresponding rule implementation.

Changes:
- Created ban_tslint_comment.go with rule implementation
- Registered the rule in internal/config/config.go
- Rule detects both single-line and multi-line tslint directives

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@claude
Copy link

claude bot commented Nov 5, 2025

Pull Request Review: Enable ban-tslint-comment test in configuration

Summary

This PR adds implementation for the @typescript-eslint/ban-tslint-comment rule and enables its test suite. The changes include a new Go implementation file, registration in the config, and enabling the test in the test configuration.

Code Quality & Best Practices

Strengths

  1. Clear structure: The implementation follows the established pattern used in similar rules like ban_ts_comment and triple_slash_reference
  2. Good documentation: Comments explain the regex patterns and function purposes
  3. Proper registration: Rule is correctly registered in internal/config/config.go
  4. Follows Go conventions: Package naming, function naming, and structure are idiomatic

Issues & Recommendations

1. Critical Bug: Missing Directive Variants (ban_tslint_comment.go:13-16)

The regex patterns don't match all the test cases. Looking at the test file, there are cases with colons after directives:

  • /* tslint:disable:rule1 rule2 rule3... */ (line 55 in test)
  • /* tslint:enable:rule1 rule2 rule3... */ (line 69 in test)

Current regex:

multiLineTslintRegex = regexp.MustCompile(`^\/\*\s*tslint:(disable|enable)`)

This will match /* tslint:disable:rule1... but the implementation doesn't account for the colon separator and rule names that follow.

Recommendation: The regex should be:

multiLineTslintRegex = regexp.MustCompile(`^\/\*\s*tslint:(disable|enable)(?::|\s|$)`)
singleLineTslintRegex = regexp.MustCompile(`^\/\/\s*tslint:(disable|enable|disable-next-line|disable-line)(?::|\s|$)`)

This ensures we match the directive whether it's followed by a colon (with rules), whitespace, or end of comment.

2. Performance: Inefficient Comment Scanning (ban_tslint_comment.go:37-76)

The manual character-by-character scanning is inefficient and error-prone. Issues:

  • O(n) scan of entire file: Scans every character even in non-comment code
  • No string escaping handling: Could incorrectly identify comments in strings
  • Incomplete multi-line comment parsing: Doesn't handle unterminated comments (line 60-66)

Comparison with triple_slash_reference.go: That rule uses strings.Split(text, "\n") and line-by-line processing, which is simpler and more maintainable for line-based patterns.

Recommendation: Consider using the TypeScript AST's built-in comment extraction if available, or leverage a line-by-line approach for better clarity. The current approach is borrowed from ban_ts_comment.go, but the added complexity may not be justified for this simpler rule.

3. Missing Edge Case: Inline Comments (ban_tslint_comment.go:97-109)

Test case at line 97-108 shows: someCode(); // tslint:disable-line

The current implementation will match this correctly, but the position calculation may be off. The comment reports the entire range from the start of someCode() potentially, when it should only highlight the comment portion.

Verification needed: Test that the commentStart position correctly identifies where the comment begins, not where code before it starts.

4. Code Duplication (ban_tslint_comment.go:80-93)

The checkComment function has redundant code:

var matches []string

if isMultiLine {
    match := multiLineTslintRegex.FindStringSubmatch(commentText)
    if match != nil {
        matches = match
    }
} else {
    match := singleLineTslintRegex.FindStringSubmatch(commentText)
    if match != nil {
        matches = match
    }
}

if matches == nil {
    return
}

The matches variable serves no purpose - you can directly check the match result.

Recommendation:

var regex *regexp.Regexp
if isMultiLine {
    regex = multiLineTslintRegex
} else {
    regex = singleLineTslintRegex
}

if !regex.MatchString(commentText) {
    return
}

Potential Bugs

1. Multi-line Comment End Detection (ban_tslint_comment.go:60-66)

for commentEnd+1 < length {
    if text[commentEnd] == '*' && text[commentEnd+1] == '/' {
        commentEnd += 2
        break
    }
    commentEnd++
}

If a multi-line comment is not properly terminated (reaches EOF), this loop continues until EOF but commentEnd could be out of bounds. The check should be commentEnd < length not commentEnd+1 < length for safety.

2. Position Tracking Issues (ban_tslint_comment.go:54, 69)

After finding a comment, the code does:

pos = lineEnd  // or pos = commentEnd

But if the file has Windows line endings (\r\n), the position tracking could be off by one. The code at line 49 checks for both \n and \r separately but doesn't handle the \r\n sequence as a single newline.

3. Test Case Coverage Gap

The test expects output to be empty string for removed comments (lines 38, 52, etc.), suggesting the rule should support auto-fixing. However, the Go implementation doesn't provide any fix/suggestion mechanism - it only reports diagnostics.

Question: Does the RSLint framework require explicit fix handlers, or are they optional?

Performance Considerations

  1. Regex compilation: The regex patterns are compiled once at package init time (good practice)
  2. Full file scan: The processComments function scans the entire file character-by-character. For large files, this could be slow.
  3. No early exit: Even after finding comments, continues scanning entire file

Recommendation: If the TypeScript AST provides comment nodes, use those instead of manual scanning. This would be both faster and more reliable.

Security Concerns

No significant security issues identified. The implementation:

  • Uses standard library regex (no external dependencies)
  • Doesn't execute or evaluate any user code
  • Doesn't modify files (read-only analysis)
  • Bounded by input file size (no infinite loops if file ends properly)

Minor concern: Malformed files with unterminated multi-line comments could cause the scanner to read to EOF, but this is expected behavior for a linter.

Test Coverage

The test file (ban-tslint-comment.test.ts) appears comprehensive:

  • ✅ Valid cases (non-tslint comments)
  • ✅ Invalid cases (all tslint directive types)
  • ✅ Inline comments
  • ✅ Multi-line comments
  • ✅ Comments with rule specifications

Missing from test review:

  • No test file for the Go implementation itself (e.g., ban_tslint_comment_test.go)
  • Other similar rules have _test.go files alongside implementation

Config Integration

The registration in config.go looks correct and follows the pattern:

GlobalRuleRegistry.Register("@typescript-eslint/ban-tslint-comment", ban_tslint_comment.BanTslintCommentRule)

Alphabetically ordered in the imports and registration calls. ✅

Recommendations Summary

High Priority

  1. ⚠️ Fix regex to handle directive variants with colons (:rule1 rule2...)
  2. ⚠️ Verify position calculations for inline comments are correct
  3. ⚠️ Add bounds checking for unterminated multi-line comments

Medium Priority

  1. Simplify checkComment to remove redundant matches variable
  2. Consider adding ban_tslint_comment_test.go for unit testing the Go code
  3. Handle Windows line endings (\r\n) correctly in position tracking

Low Priority

  1. Consider leveraging AST comment nodes if available (performance improvement)
  2. Add early exit optimizations if performance becomes an issue

Overall Assessment

This is a solid implementation that follows established patterns in the codebase. The main concerns are around regex pattern completeness and some edge cases in comment parsing. The changes are well-structured and properly integrated.

Recommendation: Request changes to address the regex pattern issue (#1) before merging, as it will cause test failures. The other issues are improvements that can be addressed in follow-up PRs.


✅ Code follows repository patterns and conventions
⚠️ Regex patterns need adjustment for test compatibility
✅ Proper registration and configuration
✅ Good test coverage in test suite

- Add ReportRangeWithFixes method to rule context
- Implement ReportRangeWithFixes in linter
- Update ban-tslint-comment rule to provide automatic fixes
- Fixes remove tslint comments from code appropriately
  - Standalone comments: removes entire line including newline
  - Inline comments: removes only the comment, preserves code

Fixes the test failures for ban-tslint-comment by adding the missing autofix functionality expected by the test suite.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@claude
Copy link

claude bot commented Nov 5, 2025

Code Review: ban-tslint-comment Rule Implementation

Thank you for this contribution! This PR adds support for the TypeScript-ESLint ban-tslint-comment rule. I've reviewed the changes and have feedback on code quality, potential issues, and best practices.


Summary

This PR successfully:

  • Enables the ban-tslint-comment test in the test configuration
  • Implements the rule in Go (ban_tslint_comment.go)
  • Adds autofix functionality via ReportRangeWithFixes
  • Registers the rule in the global registry

Code Quality & Best Practices ✅

Strengths:

  1. Consistent with codebase patterns - The implementation follows the same structure as ban_ts_comment.go, which is excellent
  2. Clean separation of concerns - Comment processing, detection, and fixing are well-separated
  3. Good use of regex - Appropriate regex patterns for single-line and multi-line TSLint directives
  4. Proper fix implementation - Handles both standalone and inline comments correctly

Minor improvements:

  1. Regex patterns could be more specific (ban_tslint_comment.go:12-16):

    // Current patterns match anywhere after //
    singleLineTslintRegex = regexp.MustCompile(`^\/\/\/?\s*tslint:(disable|enable|disable-next-line|disable-line)`)
    
    // Consider: Should we validate the format more strictly?
    // e.g., ensure word boundaries after the directive type?
  2. Magic number for character limit (ban_tslint_comment.go:141-142):
    The code checks character positions but could benefit from clearer variable names:

    // Consider naming this to clarify what's being removed
    removeStart := commentStart
    for removeStart > lineStart && (fullText[removeStart-1] == ' ' || fullText[removeStart-1] == '\t') {
        removeStart--
    }

Potential Bugs & Edge Cases ⚠️

1. Unicode handling in comment processing (ban_tslint_comment.go:38-82)
The byte-based iteration could cause issues with multi-byte UTF-8 characters:

for pos < length {
    if text[pos] == '/' && text[pos+1] == '/' {  // ⚠️ Assumes ASCII

Impact: Low - Comments are typically ASCII, but could fail on files with UTF-8 characters before comments
Recommendation: Consider using range over strings for proper rune handling, or add a comment documenting the ASCII assumption

2. Potential index out of bounds (ban_tslint_comment.go:135-137)

if text[pos] == '/' && text[pos+1] == '/' {

The bounds check pos+1 < length is done at line 135, but accessing text[pos+1] could still panic if the string is unexpectedly mutated.
Impact: Very low - protected by outer condition, but defensive
Recommendation: Current implementation is safe due to the outer if pos+1 < length check

3. Newline handling edge case (ban_tslint_comment.go:149-152)

if removeEnd < len(fullText) && (fullText[removeEnd] == '\n' || fullText[removeEnd] == '\r') {
    removeEnd++
    // Handle \r\n
    if removeEnd < len(fullText) && fullText[removeEnd-1] == '\r' && fullText[removeEnd] == '\n' {

Issue: This logic has a subtle bug. It increments removeEnd first, then checks fullText[removeEnd-1] == '\r', which would be checking the character that was just added, not the original character.

Example:

  • If we have \r\n, after first increment removeEnd points to \n
  • Then fullText[removeEnd-1] is \r (correct)
  • Then fullText[removeEnd] is \n (correct by coincidence)

But if we have just \n:

  • After increment, removeEnd points past \n
  • Then we check fullText[removeEnd-1] == '\r' (which is \n, so false)
  • Then we'd check fullText[removeEnd] == '\n' (which would be the next character)

Recommendation: Rewrite for clarity:

// Include trailing newline(s)
if removeEnd < len(fullText) {
    if fullText[removeEnd] == '\r' && removeEnd+1 < len(fullText) && fullText[removeEnd+1] == '\n' {
        removeEnd += 2  // \r\n
    } else if fullText[removeEnd] == '\n' || fullText[removeEnd] == '\r' {
        removeEnd++     // \n or \r
    }
}

4. Multi-line comment termination (ban_tslint_comment.go:168-175)

for commentEnd+1 < length {
    if text[commentEnd] == '*' && text[commentEnd+1] == '/' {
        commentEnd += 2
        break
    }
    commentEnd++
}

If a multi-line comment is not properly terminated, this could scan to the end of the file.
Impact: Low - malformed code shouldn't be common
Recommendation: Current behavior is acceptable (matches how the parser would handle it)


Performance Considerations 🚀

1. Single-pass scanning - Excellent
The implementation does a single O(n) scan of the source text, which is optimal.

2. Regex compilation (ban_tslint_comment.go:12-16)
The regexes are compiled as package-level variables, which is the correct approach for performance. ✅

3. String operations in tight loop (ban_tslint_comment.go:119-142)
Multiple string slicing and character comparisons:

for removeStart > lineStart && (fullText[removeStart-1] == ' ' || fullText[removeStart-1] == '\t') {
    removeStart--
}

Impact: Minimal - this is a small backward scan
Status: Acceptable ✅

4. Memory efficiency
The code avoids creating unnecessary string copies in most places. Good! ✅


Security Concerns 🔒

No significant security issues identified

  1. No unsafe operations - All array/string access is bounds-checked
  2. No user input injection - Regex patterns are hardcoded, not user-supplied
  3. No resource exhaustion - Single-pass algorithm with linear complexity
  4. Safe regex patterns - No catastrophic backtracking possible in the current regexes

Test Coverage 📊

Test file analysis (ban-tslint-comment.test.ts):

Coverage is good

  • Valid cases: Comments that should NOT trigger the rule
  • Invalid cases: All TSLint directive types (disable, enable, disable-next-line, disable-line)
  • Autofix verification: Standalone vs inline comments
  • Edge cases: Multi-line code with comments

Potential missing test cases:

  1. Multi-line comments with extra content - Do we correctly ignore /* some text tslint:disable more text */?
  2. Multiple directives on same line - What about // tslint:disable-next-line // tslint:disable-line?
  3. Nested comments (if the language supports them)
  4. Unicode in comments - // tslint:disable 日本語コメント
  5. Windows vs Unix line endings - Test \r\n explicitly
  6. Comments at end of file without trailing newline

Architecture & Integration 🏗️

1. Rule context integration (linter.go:88-100) ✅
The addition of ReportRangeWithFixes to the linter context is clean and follows the existing pattern for ReportRangeWithSuggestions.

2. Rule registration (config.go:367) ✅
Properly registered in alphabetical order.

3. Type safety (rule.go:170) ✅
Function signature is type-safe with variadic fixes parameter.


Recommendations

Priority: HIGH

  1. Fix the newline handling logic in the autofix (see bug feat: Set up TypeScript ESTree infrastructure #3 above)

Priority: MEDIUM
2. Add test cases for edge cases mentioned in the test coverage section
3. Add a comment documenting the ASCII assumption in comment scanning

Priority: LOW
4. Consider extracting magic values (space, tab characters) into named constants for clarity
5. Consider adding a maximum scan limit for unterminated multi-line comments (defensive programming)


Summary

Overall Assessment: Good

This is a solid implementation that follows the codebase conventions well. The primary concern is the potential bug in newline handling logic (#3), which should be addressed. The code is otherwise clean, performant, and secure.

Recommendation: Approve with minor changes requested for the newline handling fix.

Great work on following the existing patterns in the codebase!


🤖 Generated with Claude Code

@kdy1 kdy1 closed this Nov 5, 2025
@kdy1 kdy1 deleted the devbird/enable-ban-tslint-comment-test branch November 7, 2025 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants