Skip to content

Commit f8664b1

Browse files
justin808claude
andauthored
Fix TypeScript ESLint Phase 2a: Simple non-breaking fixes (27 errors) (#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]>
1 parent 2ca0cb3 commit f8664b1

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

package/types.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ type WebSocketType = "sockjs" | "ws"
6363
* @see {import('webpack-dev-server').Configuration}
6464
*/
6565
export interface DevServerConfig {
66-
allowed_hosts?: "all" | "auto" | string | string[]
66+
allowed_hosts?: string | string[]
6767
bonjour?: boolean | Record<string, unknown> // bonjour.BonjourOptions
6868
client?: Record<string, unknown> // Client
6969
compress?: boolean
7070
dev_middleware?: Record<string, unknown> // webpackDevMiddleware.Options
7171
headers?: Header | (() => Header)
7272
history_api_fallback?: boolean | Record<string, unknown> // HistoryApiFallbackOptions
7373
hmr?: "only" | boolean
74-
host?: "local-ip" | "local-ipv4" | "local-ipv6" | string
74+
host?: string
7575
http2?: boolean
7676
https?: boolean | https.ServerOptions
7777
ipc?: boolean | string
@@ -85,23 +85,21 @@ export interface DevServerConfig {
8585
| string[]
8686
| Record<string, unknown>
8787
| Record<string, unknown>[]
88-
port?: "auto" | string | number
88+
port?: string | number
8989
proxy?: unknown // ProxyConfigMap | ProxyConfigArray
9090
setup_exit_signals?: boolean
91-
static?: boolean | string | unknown // Static | Array<string | Static>
92-
watch_files?: string | string[] | unknown // WatchFiles | Array<WatchFiles | string>
91+
static?: unknown // Static | Array<string | Static>
92+
watch_files?: unknown // WatchFiles | Array<WatchFiles | string>
9393
web_socket_server?:
9494
| string
9595
| boolean
96-
| WebSocketType
9796
| {
98-
type?: string | boolean | WebSocketType
97+
type?: string | boolean
9998
options?: Record<string, unknown>
10099
}
101100
server?:
102101
| string
103102
| boolean
104-
| ServerType
105-
| { type?: string | boolean | ServerType; options?: https.ServerOptions }
103+
| { type?: string | boolean; options?: https.ServerOptions }
106104
[otherWebpackDevServerConfigKey: string]: unknown
107105
}

package/utils/debug.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@ const isDebugMode = (): boolean => {
1818

1919
const debug = (message: string, ...args: unknown[]): void => {
2020
if (isDebugMode()) {
21-
// eslint-disable-next-line no-console
2221
console.log(`[Shakapacker] ${message}`, ...args)
2322
}
2423
}
2524

2625
const warn = (message: string, ...args: unknown[]): void => {
27-
// eslint-disable-next-line no-console
2826
console.warn(`[Shakapacker] WARNING: ${message}`, ...args)
2927
}
3028

3129
const error = (message: string, ...args: unknown[]): void => {
32-
// eslint-disable-next-line no-console
3330
console.error(`[Shakapacker] ERROR: ${message}`, ...args)
3431
}
3532

3633
const info = (message: string, ...args: unknown[]): void => {
3734
if (isDebugMode()) {
38-
// eslint-disable-next-line no-console
3935
console.info(`[Shakapacker] INFO: ${message}`, ...args)
4036
}
4137
}

package/utils/getStyleRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const inliningCss = require("./inliningCss")
66

77
interface StyleRule {
88
test: RegExp
9-
use: any[]
9+
use: unknown[]
1010
type?: string
1111
}
1212

1313
const getStyleRule = (
1414
test: RegExp,
15-
preprocessors: any[] = []
15+
preprocessors: unknown[] = []
1616
): StyleRule | null => {
1717
if (moduleExists("css-loader")) {
1818
const tryPostcss = () =>

package/utils/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ const packageFullVersion = (packageName: string): string => {
6363
// eslint-disable-next-line import/no-dynamic-require, global-require
6464
const packageJson = require(packageJsonPath) as { version: string }
6565
return packageJson.version
66-
} catch (error: any) {
66+
} catch (error: unknown) {
6767
// Re-throw the error with proper code to maintain compatibility with babel preset
6868
// The preset expects MODULE_NOT_FOUND errors to handle missing core-js gracefully
69-
if (error.code === "MODULE_NOT_FOUND") {
69+
if ((error as NodeJS.ErrnoException).code === "MODULE_NOT_FOUND") {
7070
throw error
7171
}
7272
// For other errors, warn and re-throw

package/utils/requireOrError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface ErrorWithCause extends Error {
66
cause?: unknown
77
}
88

9-
const requireOrError = (moduleName: string): any => {
9+
const requireOrError = (moduleName: string): unknown => {
1010
try {
1111
return require(moduleName)
1212
} catch (originalError: unknown) {

package/webpackDevServerConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ interface WebpackDevServerConfig {
2525
[key: string]: unknown
2626
}
2727
client?: Record<string, unknown>
28-
allowedHosts?: "all" | "auto" | string | string[]
28+
allowedHosts?: string | string[]
2929
bonjour?: boolean | Record<string, unknown>
3030
compress?: boolean
3131
headers?: Record<string, unknown> | (() => Record<string, unknown>)
32-
host?: "local-ip" | "local-ipv4" | "local-ipv6" | string
32+
host?: string
3333
http2?: boolean
3434
https?: boolean | Record<string, unknown>
3535
ipc?: boolean | string
@@ -42,12 +42,12 @@ interface WebpackDevServerConfig {
4242
| string[]
4343
| Record<string, unknown>
4444
| Record<string, unknown>[]
45-
port?: "auto" | string | number
45+
port?: string | number
4646
proxy?: unknown
4747
server?: string | boolean | Record<string, unknown>
4848
setupExitSignals?: boolean
4949
setupMiddlewares?: (middlewares: unknown[], devServer: unknown) => unknown[]
50-
watchFiles?: string | string[] | unknown
50+
watchFiles?: unknown
5151
webSocketServer?: string | boolean | Record<string, unknown>
5252
[key: string]: unknown
5353
}

0 commit comments

Comments
 (0)