Skip to content

Commit f81f6e5

Browse files
authored
Fix TypeScript ESLint errors (Phase 1): Auto-fixes and simple manual fixes (#788)
## Summary This PR addresses the first batch of ESLint errors in TypeScript files that were previously suppressed via the ignore pattern `package/**/*.ts` in `eslint.config.js`. Part of #783 - TypeScript ESLint Technical Debt resolution. ## Changes Made ### Auto-fixes Applied - Import ordering and organization (import/order, import/first, import/newline-after-import) - Removed unnecessary type assertions (@typescript-eslint/no-unnecessary-type-assertion) ### Manual Fixes - Replaced `@ts-ignore` with `@ts-expect-error` in .d.ts files for webpack optional peer dependency - Removed unnecessary `@ts-expect-error` from runtime .ts files (webpack is installed in dev environment) - Replaced `any` with `unknown` in loader option interfaces - Fixed `no-use-before-define` error by moving `isValidDevServerConfig` before `isValidConfig` ## Error Reduction - **Before**: 293 ESLint errors - **After**: 247 ESLint errors - **Fixed**: 46 errors (15.7% reduction) ## Testing - All existing linting passes with standard ignore patterns - TypeScript compilation succeeds (`tsc --noEmit`) - Pre-commit hooks pass (type checking, linting, prettier) ## 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) - Various `@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. ## Summary by CodeRabbit * **Refactor** * Reorganized imports and simplified internal code structure for improved maintainability. * Strengthened type safety by replacing permissive type definitions with stricter alternatives. * Enhanced validation mechanisms for configuration handling. * **Chores** * Updated TypeScript compiler directives for better error detection. * Applied minor code formatting improvements.
1 parent 64eb2f2 commit f81f6e5

14 files changed

Lines changed: 96 additions & 96 deletions

File tree

package/dev_server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// These are the raw shakapacker dev server config settings from the YML file with ENV overrides applied.
2+
import { DevServerConfig } from "./types"
3+
24
const { isBoolean } = require("./utils/helpers")
35
const config = require("./config")
4-
import { DevServerConfig } from "./types"
56

67
const envFetch = (key: string): string | boolean | undefined => {
78
const value = process.env[key]

package/environments/base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint global-require: 0 */
22
/* eslint import/no-dynamic-require: 0 */
33

4+
import { Dirent } from "fs"
5+
import type { Configuration, Entry } from "webpack"
6+
47
const { basename, dirname, join, relative, resolve } = require("path")
58
const { existsSync, readdirSync } = require("fs")
6-
import { Dirent } from "fs"
79
const extname = require("path-complete-extname")
8-
// @ts-ignore: webpack is an optional peer dependency (using type-only import)
9-
import type { Configuration, Entry } from "webpack"
1010
const config = require("../config")
1111
const { isProduction } = require("../env")
1212

@@ -73,7 +73,7 @@ const getEntryObject = (): Entry => {
7373
const previousPaths = entries[name]
7474
if (previousPaths) {
7575
const pathArray = Array.isArray(previousPaths)
76-
? (previousPaths as string[])
76+
? previousPaths
7777
: [previousPaths as string]
7878
pathArray.push(assetPath)
7979
entries[name] = pathArray

package/environments/development.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
* @module environments/development
44
*/
55

6-
const { merge } = require("webpack-merge")
7-
const config = require("../config")
8-
const baseConfig = require("./base")
9-
const webpackDevServerConfig = require("../webpackDevServerConfig")
10-
const { runningWebpackDevServer } = require("../env")
11-
const { moduleExists } = require("../utils/helpers")
126
import type {
137
WebpackConfigWithDevServer,
148
RspackConfigWithDevServer,
159
ReactRefreshWebpackPlugin,
1610
ReactRefreshRspackPlugin
1711
} from "./types"
1812

13+
const { merge } = require("webpack-merge")
14+
const config = require("../config")
15+
const baseConfig = require("./base")
16+
const webpackDevServerConfig = require("../webpackDevServerConfig")
17+
const { runningWebpackDevServer } = require("../env")
18+
const { moduleExists } = require("../utils/helpers")
19+
1920
/**
2021
* Base development configuration shared between webpack and rspack
2122
*/

package/environments/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* @module environments/test
44
*/
55

6+
import type { Configuration as WebpackConfiguration } from "webpack"
7+
68
const { merge } = require("webpack-merge")
79
const config = require("../config")
810
const baseConfig = require("./base")
9-
import type { Configuration as WebpackConfiguration } from "webpack"
1011

1112
interface TestConfig {
1213
mode: "development" | "production" | "none"

package/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import * as webpackMerge from "webpack-merge"
55
import { resolve } from "path"
66
import { existsSync } from "fs"
7-
// @ts-ignore: webpack is an optional peer dependency (using type-only import)
87
import type { Configuration, RuleSetRule } from "webpack"
98
import config from "./config"
109
import baseConfig from "./environments/base"

package/loaders.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// @ts-ignore: webpack is an optional peer dependency (using type-only import)
1+
// @ts-expect-error: webpack is an optional peer dependency (using type-only import)
22
import type { LoaderDefinitionFunction } from "webpack"
33

44
export interface ShakapackerLoaderOptions {
5-
[key: string]: any
5+
[key: string]: unknown
66
}
77

88
export interface ShakapackerLoader {

package/optimization/webpack.ts

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,36 @@ interface OptimizationConfig {
1919
minimizer: unknown[]
2020
}
2121

22-
const getOptimization = (): OptimizationConfig => {
23-
return {
24-
minimizer: [
25-
tryCssMinimizer(),
26-
new TerserPlugin({
27-
// SHAKAPACKER_PARALLEL env var: number of parallel workers, or true for auto (os.cpus().length - 1)
28-
// If not set or invalid, defaults to true (automatic parallelization)
29-
parallel: process.env.SHAKAPACKER_PARALLEL
30-
? Number.parseInt(process.env.SHAKAPACKER_PARALLEL, 10) || true
31-
: true,
32-
terserOptions: {
33-
parse: {
34-
// Let terser parse ecma 8 code but always output
35-
// ES5 compliant code for older browsers
36-
ecma: 8
37-
},
38-
compress: {
39-
ecma: 5,
40-
warnings: false,
41-
comparisons: false
42-
},
43-
mangle: { safari10: true },
44-
output: {
45-
ecma: 5,
46-
comments: false,
47-
ascii_only: true
48-
}
22+
const getOptimization = (): OptimizationConfig => ({
23+
minimizer: [
24+
tryCssMinimizer(),
25+
new TerserPlugin({
26+
// SHAKAPACKER_PARALLEL env var: number of parallel workers, or true for auto (os.cpus().length - 1)
27+
// If not set or invalid, defaults to true (automatic parallelization)
28+
parallel: process.env.SHAKAPACKER_PARALLEL
29+
? Number.parseInt(process.env.SHAKAPACKER_PARALLEL, 10) || true
30+
: true,
31+
terserOptions: {
32+
parse: {
33+
// Let terser parse ecma 8 code but always output
34+
// ES5 compliant code for older browsers
35+
ecma: 8
36+
},
37+
compress: {
38+
ecma: 5,
39+
warnings: false,
40+
comparisons: false
41+
},
42+
mangle: { safari10: true },
43+
output: {
44+
ecma: 5,
45+
comments: false,
46+
ascii_only: true
4947
}
50-
})
51-
].filter(Boolean)
52-
}
53-
}
48+
}
49+
})
50+
].filter(Boolean)
51+
})
5452

5553
export = {
5654
getOptimization

package/rspack/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
// Mixed require/import syntax:
55
// - Using require() for compiled JS modules that may not have proper ES module exports
66
// - Using import for type-only imports and Node.js built-in modules
7-
const webpackMerge = require("webpack-merge")
87
import { resolve } from "path"
98
import { existsSync } from "fs"
109
import type { RspackConfigWithDevServer } from "../environments/types"
10+
11+
const webpackMerge = require("webpack-merge")
1112
const config = require("../config")
1213
const baseConfig = require("../environments/base")
1314
const devServer = require("../dev_server")

package/rules/file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { dirname, sep, normalize } from "path"
2+
23
const {
34
additional_paths: additionalPaths,
45
source_path: sourcePath

package/rules/jscommon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolve } from "path"
22
import { realpathSync } from "fs"
3+
34
const {
45
source_path: sourcePath,
56
additional_paths: additionalPaths

0 commit comments

Comments
 (0)