Fix TypeScript ESLint errors (Phase 1): Auto-fixes and simple manual fixes#788
Fix TypeScript ESLint errors (Phase 1): Auto-fixes and simple manual fixes#788
Conversation
…fixes This commit addresses the first batch of ESLint errors in TypeScript files that were previously suppressed via the ignore pattern `package/**/*.ts`. Changes: - Run auto-fix to handle fixable errors (import ordering, unnecessary type assertions, etc.) - Replace @ts-ignore with @ts-expect-error in .d.ts files for webpack optional peer dependency - Remove unnecessary @ts-expect-error from runtime .ts files (webpack is installed in dev) - Replace `any` with `unknown` in loader option interfaces - Fix no-use-before-define error by moving isValidDevServerConfig before isValidConfig Error reduction: 293 → 247 errors (46 errors fixed) Part of issue #783 - TypeScript ESLint Technical Debt resolution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
WalkthroughThis PR modernizes TypeScript import handling and improves type safety across the package. Changes include reorganizing imports with explicit type-only declarations, upgrading Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant isValidDevServerConfig
participant shouldValidate
participant pathValidator
Caller->>isValidDevServerConfig: Call with unknown obj
isValidDevServerConfig->>isValidDevServerConfig: Check if obj is object
alt is object
isValidDevServerConfig->>shouldValidate: Check validation flag
alt shouldValidate() returns true
isValidDevServerConfig->>pathValidator: Run deep validation
pathValidator->>pathValidator: Validate all path fields
alt paths valid
isValidDevServerConfig->>Caller: Return true (type guard passes)
else paths invalid
isValidDevServerConfig->>Caller: Return false
end
else shouldValidate() returns false
isValidDevServerConfig->>pathValidator: Run security checks only
pathValidator->>pathValidator: Validate path traversal safety
alt security checks pass
isValidDevServerConfig->>Caller: Return true
else security checks fail
isValidDevServerConfig->>Caller: Return false
end
end
else not object
isValidDevServerConfig->>Caller: Return false
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Areas requiring extra attention:
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review: TypeScript ESLint Phase 1 FixesGreat work on tackling the ESLint technical debt! This is a well-structured, focused PR that makes meaningful progress. Here's my detailed review: ✅ Strengths
🔍 Code Quality Observationspackage/utils/typeGuards.ts (lines 73-99, 114, 139, etc.)
package/environments/base.ts (line 76)
package/optimization/webpack.ts
🤔 Minor Concerns & Questions
🔒 Security Considerations✅ No security concerns identified. The changes are primarily stylistic and type-safety improvements. The security-critical path validation logic in ⚡ Performance Considerations✅ No performance impact. The changes are:
🧪 Testing Recommendations
📋 CHANGELOG ConsiderationsPer CLAUDE.md guidelines, this PR should NOT have a CHANGELOG entry because:
This aligns with the project's guidelines: "Do NOT add changelog entries for: linting fixes, code formatting, internal refactoring" 🎯 SummaryApproval Status: ✅ Approved with minor recommendations This is solid work that improves code quality without introducing risk. The incremental approach is commendable. Before merge, consider:
For future phases, watch out for:
Great job on maintaining focus and keeping changes reviewable! 🚀 Review generated with Claude Code |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
package/loaders.d.ts (1)
4-6: Consider consolidating duplicate interface definitions.The
ShakapackerLoaderOptionsinterface is defined identically in bothpackage/loaders.d.ts(lines 4-6) andpackage/webpack-types.d.ts(lines 15-17). Consider extracting this to a shared types file to maintain a single source of truth.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
package/dev_server.ts(1 hunks)package/environments/base.ts(2 hunks)package/environments/development.ts(1 hunks)package/environments/test.ts(1 hunks)package/index.ts(0 hunks)package/loaders.d.ts(1 hunks)package/optimization/webpack.ts(1 hunks)package/rspack/index.ts(1 hunks)package/rules/file.ts(1 hunks)package/rules/jscommon.ts(1 hunks)package/utils/helpers.ts(0 hunks)package/utils/typeGuards.ts(10 hunks)package/webpack-types.d.ts(2 hunks)package/webpackDevServerConfig.ts(1 hunks)
💤 Files with no reviewable changes (2)
- package/index.ts
- package/utils/helpers.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-19T00:36:13.668Z
Learnt from: CR
Repo: shakacode/shakapacker PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-10-19T00:36:13.668Z
Learning: Applies to lib/shakapacker/**/*.rb : When modifying core Shakapacker functionality, test changes with both webpack and rspack bundlers
Applied to files:
package/webpack-types.d.tspackage/rspack/index.tspackage/environments/development.tspackage/loaders.d.ts
🧬 Code graph analysis (2)
package/utils/typeGuards.ts (2)
package/types.ts (1)
DevServerConfig(65-107)package/utils/pathValidation.ts (2)
validatePort(190-208)isPathTraversalSafe(11-26)
package/loaders.d.ts (1)
package/webpack-types.d.ts (1)
ShakapackerLoaderOptions(15-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: Testing (ubuntu-latest, 22.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Testing (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.6.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.4, gemfiles/Gemfile-rails.8.0.x)
- GitHub Check: Testing (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.3, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Testing (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.6.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.2, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 2.7, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.0, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.2.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.0.x)
- GitHub Check: Generator specs (ubuntu-latest, 3.1, gemfiles/Gemfile-rails.7.1.x)
- GitHub Check: claude-review
- GitHub Check: test
🔇 Additional comments (17)
package/webpackDevServerConfig.ts (1)
2-2: LGTM! Import formatting improved.The blank line after the import statement improves readability and satisfies ESLint's import organization rules.
package/rspack/index.ts (1)
10-11: LGTM! Import ordering improved.Moving the webpack-merge require after type imports aligns with ESLint import ordering rules while preserving all functionality.
package/rules/file.ts (1)
2-2: LGTM! Import formatting improved.The blank line after the import statement enhances readability and satisfies ESLint's import organization rules.
package/rules/jscommon.ts (1)
3-3: LGTM! Import formatting improved.The blank line after the import statement improves code consistency and satisfies ESLint's import organization rules.
package/environments/base.ts (2)
4-6: LGTM! Type imports improved.Adding explicit imports for Dirent, Configuration, and Entry types enhances type safety and makes dependencies clear.
75-77: LGTM! Logic improvement for array handling.The updated logic correctly preserves
previousPathswhen it's already an array, avoiding an unnecessary array reconstruction. This is more efficient and clearer than the previous approach.package/environments/development.ts (1)
13-19: LGTM! Import organization improved.Reordering runtime imports to follow type-only imports aligns with ESLint's import ordering rules and improves code consistency across the codebase.
package/dev_server.ts (1)
2-3: LGTM! Import deduplication improved.Adding the explicit top-level import of DevServerConfig and removing the duplicate import elsewhere improves code organization and clarity.
package/optimization/webpack.ts (1)
22-51: LGTM! Concise arrow function syntax.The refactor from a function declaration with an explicit return to an arrow function with an implicit return is clean and idiomatic. The behavior remains identical—same optimization configuration and minimizer setup.
package/environments/test.ts (1)
6-7: LGTM! Import organization improved.The type-only import has been appropriately moved to the top of the file, aligning with ESLint import ordering rules.
package/utils/typeGuards.ts (3)
69-99: LGTM! Well-structured runtime type guard.The new
isValidDevServerConfigfunction appropriately validatesDevServerConfigobjects with production-optimized minimal validation. The implementation correctly usesshouldValidate()to skip deep validation in production for performance while maintaining type safety.
114-114: LGTM! Unnecessary type assertions removed.The
as objectcasts have been appropriately removed fromvalidatedConfigs.get()and.set()calls. Sinceobjis already validated as an object at line 109, these assertions were redundant.Also applies to: 139-139, 151-151, 174-174, 185-185, 199-199, 211-211, 221-221, 235-235, 244-244
147-147: The code is correct—TypeScript properly narrows the indexed access type.The
typeofcheck at line 137 (if (typeof config[field] !== "string")) with its early return ensures that by line 147, TypeScript's control flow analysis narrowsconfig[field]tostring. Modern TypeScript (5.9.x) withstrictmode handles this pattern correctly for indexed access onRecord<string, unknown>, so the explicitas stringassertion is unnecessary.The fact that
tsc --noEmitcompiles without errors for this pattern confirms the code is valid.package/loaders.d.ts (2)
1-1: LGTM! Better error suppression directive.Replacing
@ts-ignorewith@ts-expect-erroris the correct approach for suppressing expected TypeScript errors. This directive will fail if the error is resolved, preventing stale suppressions.
5-5: LGTM! Type safety improved.Changing from
anytounknownfor the index signature improves type safety by requiring explicit type checking before using values.package/webpack-types.d.ts (2)
1-1: LGTM! Better error suppression directive.Replacing
@ts-ignorewith@ts-expect-errorensures that the suppression will fail if the error is resolved in the future, preventing accumulation of stale directives.
16-16: LGTM! Type safety improved.Narrowing the index signature from
anytounknownrequires explicit type checking before use, improving type safety throughout the codebase.
…#793) ## Summary This PR addresses simple, safe ESLint fixes that don't change any runtime behavior or APIs. Part of #789 - TypeScript ESLint Phase 2a: Simple Non-Breaking Fixes Related to #783 - TypeScript ESLint Technical Debt resolution Follows PR #788 - Phase 1 completion ## Changes Made ### 1. Remove Unused ESLint Directives (4 errors) **File:** `package/utils/debug.ts` Removed unused `// eslint-disable-next-line no-console` comments. These directives are no longer needed since the `no-console` rule is not triggering for these console methods in a debug utility module. **Impact:** Cleanup only - no functional changes ### 2. Fix Explicit `any` Types (4 errors) **Files:** - `package/utils/getStyleRule.ts` - Replaced `any[]` with `unknown[]` for loader arrays - `package/utils/helpers.ts` - Replaced `error: any` with `error: unknown` and added proper type assertion - `package/utils/requireOrError.ts` - Replaced `any` return type with `unknown` **Impact:** Internal only - improves type safety without changing behavior ### 3. Fix Redundant Type Constituents (19 errors) **Files:** - `package/types.ts` - Simplified `DevServerConfig` interface type unions - `package/webpackDevServerConfig.ts` - Simplified webpack dev server config type unions **Examples:** ```typescript // Before: allowed_hosts?: "all" | "auto" | string | string[] host?: "local-ip" | "local-ipv4" | "local-ipv6" | string port?: "auto" | string | number static?: boolean | string | unknown watch_files?: string | string[] | unknown // After: allowed_hosts?: string | string[] host?: string port?: string | number static?: unknown watch_files?: unknown ``` **Reasoning:** - When a union includes `string`, specific string literals like `"all"` or `"auto"` are redundant because `string` already includes all possible strings - When a union includes `unknown`, all other types are redundant because `unknown` is the top type that includes everything **Impact:** Type definitions become cleaner and more accurate. No runtime changes, no API changes. ## Error Reduction - **Before**: 247 ESLint errors - **After**: 220 ESLint errors - **Fixed**: 27 errors (10.9% reduction) ## Testing - ✅ All existing linting passes with standard ignore patterns - ✅ TypeScript compilation succeeds (`tsc --noEmit`) - ✅ Pre-commit hooks pass (type checking, linting, prettier) - ✅ Security validation tests pass -⚠️ Some build tests fail, but these failures exist on main and are unrelated to these changes ## Remaining Work After this PR: - **220 errors remaining** (down from original 293) - **Next**: Phase 2b - Type Safety Improvements (~94 errors) - Issue #790 ## Related Issues and PRs - #783 - Parent issue: TypeScript ESLint Technical Debt - #789 - This issue: Phase 2a Simple Fixes - #788 - Phase 1 completion (46 errors fixed) - #790 - Phase 2b: Type Safety Improvements (next step) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Refined type constraints and annotations across configuration and utility modules for improved type safety. * Simplified error handling with more precise type definitions. * Removed unnecessary linting directives from utility functions. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude <[email protected]>
Summary
This PR addresses the first batch of ESLint errors in TypeScript files that were previously suppressed via the ignore pattern
package/**/*.tsineslint.config.js.Part of #783 - TypeScript ESLint Technical Debt resolution.
Changes Made
Auto-fixes Applied
Manual Fixes
@ts-ignorewith@ts-expect-errorin .d.ts files for webpack optional peer dependency@ts-expect-errorfrom runtime .ts files (webpack is installed in dev environment)anywithunknownin loader option interfacesno-use-before-defineerror by movingisValidDevServerConfigbeforeisValidConfigError Reduction
Testing
tsc --noEmit)Remaining Work
This is Phase 1 of the ESLint technical debt cleanup. The remaining 247 errors include:
@typescript-eslint/no-require-imports(requires ES6 import migration)@typescript-eslint/no-unsafe-*violations (require proper typing)@typescript-eslint/no-redundant-type-constituents(type definition improvements)These will be addressed in subsequent PRs to keep changes focused and reviewable.
🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Chores