Skip to content

Commit 908f59d

Browse files
authored
chore: enable some Rslint rules (#11869)
* chore: enable some Rslint rules * fix * fix * fix * chore: update api.md
1 parent 35effc2 commit 908f59d

File tree

11 files changed

+40
-56
lines changed

11 files changed

+40
-56
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint:js": "pnpm run lint-ci:js --write",
3434
"lint-ci:js": "biome check --diagnostic-level=warn --no-errors-on-unmatched --max-diagnostics=none --error-on-warnings",
3535
"lint:rs": "cargo clippy --workspace --all-targets",
36-
"lint:type": "rslint --config rslint.json --max-warnings=2486",
36+
"lint:type": "rslint --config rslint.json --max-warnings=2456",
3737
"build:binding:dev": "pnpm --filter @rspack/binding run build:dev",
3838
"build:binding:debug": "pnpm --filter @rspack/binding run build:debug",
3939
"build:binding:ci": "pnpm --filter @rspack/binding run build:ci",
@@ -101,4 +101,4 @@
101101
"esbuild"
102102
]
103103
}
104-
}
104+
}

packages/rspack/etc/core.api.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ export class Compilation {
955955
log: liteTapable.SyncBailHook<[string, LogEntry], true>;
956956
additionalAssets: any;
957957
optimizeModules: liteTapable.SyncBailHook<Iterable<Module>, void>;
958-
afterOptimizeModules: liteTapable.SyncHook<Iterable<Module>, void>;
958+
afterOptimizeModules: liteTapable.SyncHook<Iterable<Module>>;
959959
optimizeTree: liteTapable.AsyncSeriesHook<[
960960
Iterable<Chunk>,
961961
Iterable<Module>
@@ -965,21 +965,18 @@ export class Compilation {
965965
Iterable<Module>
966966
], void>;
967967
finishModules: liteTapable.AsyncSeriesHook<[Iterable<Module>], void>;
968-
chunkHash: liteTapable.SyncHook<[Chunk, Hash], void>;
969-
chunkAsset: liteTapable.SyncHook<[Chunk, string], void>;
968+
chunkHash: liteTapable.SyncHook<[Chunk, Hash]>;
969+
chunkAsset: liteTapable.SyncHook<[Chunk, string]>;
970970
processWarnings: liteTapable.SyncWaterfallHook<[WebpackError_2[]]>;
971-
succeedModule: liteTapable.SyncHook<[Module], void>;
972-
stillValidModule: liteTapable.SyncHook<[Module], void>;
973-
statsPreset: liteTapable.HookMap<liteTapable.SyncHook<[
974-
Partial<StatsOptions>,
975-
CreateStatsOptionsContext
976-
], void>>;
971+
succeedModule: liteTapable.SyncHook<[Module]>;
972+
stillValidModule: liteTapable.SyncHook<[Module]>;
973+
statsPreset: liteTapable.HookMap<liteTapable.SyncHook<[Partial<StatsOptions>, CreateStatsOptionsContext]>>;
977974
statsNormalize: liteTapable.SyncHook<[
978975
Partial<StatsOptions>,
979976
CreateStatsOptionsContext
980-
], void>;
981-
statsFactory: liteTapable.SyncHook<[StatsFactory, StatsOptions], void>;
982-
statsPrinter: liteTapable.SyncHook<[StatsPrinter, StatsOptions], void>;
977+
]>;
978+
statsFactory: liteTapable.SyncHook<[StatsFactory, StatsOptions]>;
979+
statsPrinter: liteTapable.SyncHook<[StatsPrinter, StatsOptions]>;
983980
buildModule: liteTapable.SyncHook<[Module]>;
984981
executeModule: liteTapable.SyncHook<[
985982
ExecuteModuleArgument,
@@ -988,10 +985,10 @@ export class Compilation {
988985
additionalTreeRuntimeRequirements: liteTapable.SyncHook<[
989986
Chunk,
990987
Set<string>
991-
], void>;
988+
]>;
992989
runtimeRequirementInTree: liteTapable.HookMap<liteTapable.SyncBailHook<[Chunk, Set<string>], void>>;
993-
runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk], void>;
994-
seal: liteTapable.SyncHook<[], void>;
990+
runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk]>;
991+
seal: liteTapable.SyncHook<[]>;
995992
afterSeal: liteTapable.AsyncSeriesHook<[], void>;
996993
needAdditionalPass: liteTapable.SyncBailHook<[], boolean>;
997994
}>;
@@ -1784,7 +1781,7 @@ type DevServerOptions<A extends BasicApplication = BasicApplication, S extends B
17841781
open?: string | boolean | Open_2 | (string | Open_2)[] | undefined;
17851782
setupExitSignals?: boolean | undefined;
17861783
client?: boolean | ClientConfiguration | undefined;
1787-
headers?: Headers_2 | ((req: Request_2, res: Response_2, context: DevMiddlewareContext<Request_2, Response_2> | undefined) => Headers_2) | undefined;
1784+
headers?: Headers_2 | ((req: Request_2, res: Response_2, context: DevMiddlewareContext | undefined) => Headers_2) | undefined;
17881785
onListening?: ((devServer: Server_4) => void) | undefined;
17891786
setupMiddlewares?: ((middlewares: DevServerMiddleware[], devServer: Server_4) => DevServerMiddleware[]) | undefined;
17901787
};
@@ -3281,9 +3278,9 @@ type IntermediateFileSystem = InputFileSystem & OutputFileSystem & IntermediateF
32813278
type IntermediateFileSystemExtras = {
32823279
rename: (arg0: PathLike, arg1: PathLike, arg2: (arg0: null | NodeJS.ErrnoException) => void) => void;
32833280
mkdirSync: MkdirSync;
3284-
write: Write<Buffer>;
3281+
write: Write;
32853282
open: Open;
3286-
read: Read<Buffer>;
3283+
read: Read;
32873284
close: (arg0: number, arg1: (arg0: null | NodeJS.ErrnoException) => void) => void;
32883285
};
32893286

packages/rspack/src/Compilation.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class Compilation {
218218
log: liteTapable.SyncBailHook<[string, LogEntry], true>;
219219
additionalAssets: any;
220220
optimizeModules: liteTapable.SyncBailHook<Iterable<Module>, void>;
221-
afterOptimizeModules: liteTapable.SyncHook<Iterable<Module>, void>;
221+
afterOptimizeModules: liteTapable.SyncHook<Iterable<Module>>;
222222
optimizeTree: liteTapable.AsyncSeriesHook<
223223
[Iterable<Chunk>, Iterable<Module>]
224224
>;
@@ -227,38 +227,33 @@ export class Compilation {
227227
void
228228
>;
229229
finishModules: liteTapable.AsyncSeriesHook<[Iterable<Module>], void>;
230-
chunkHash: liteTapable.SyncHook<[Chunk, Hash], void>;
231-
chunkAsset: liteTapable.SyncHook<[Chunk, string], void>;
230+
chunkHash: liteTapable.SyncHook<[Chunk, Hash]>;
231+
chunkAsset: liteTapable.SyncHook<[Chunk, string]>;
232232
processWarnings: liteTapable.SyncWaterfallHook<[WebpackError[]]>;
233-
succeedModule: liteTapable.SyncHook<[Module], void>;
234-
stillValidModule: liteTapable.SyncHook<[Module], void>;
233+
succeedModule: liteTapable.SyncHook<[Module]>;
234+
stillValidModule: liteTapable.SyncHook<[Module]>;
235235

236236
statsPreset: liteTapable.HookMap<
237-
liteTapable.SyncHook<
238-
[Partial<StatsOptions>, CreateStatsOptionsContext],
239-
void
240-
>
237+
liteTapable.SyncHook<[Partial<StatsOptions>, CreateStatsOptionsContext]>
241238
>;
242239
statsNormalize: liteTapable.SyncHook<
243-
[Partial<StatsOptions>, CreateStatsOptionsContext],
244-
void
240+
[Partial<StatsOptions>, CreateStatsOptionsContext]
245241
>;
246-
statsFactory: liteTapable.SyncHook<[StatsFactory, StatsOptions], void>;
247-
statsPrinter: liteTapable.SyncHook<[StatsPrinter, StatsOptions], void>;
242+
statsFactory: liteTapable.SyncHook<[StatsFactory, StatsOptions]>;
243+
statsPrinter: liteTapable.SyncHook<[StatsPrinter, StatsOptions]>;
248244

249245
buildModule: liteTapable.SyncHook<[Module]>;
250246
executeModule: liteTapable.SyncHook<
251247
[ExecuteModuleArgument, ExecuteModuleContext]
252248
>;
253249
additionalTreeRuntimeRequirements: liteTapable.SyncHook<
254-
[Chunk, Set<string>],
255-
void
250+
[Chunk, Set<string>]
256251
>;
257252
runtimeRequirementInTree: liteTapable.HookMap<
258253
liteTapable.SyncBailHook<[Chunk, Set<string>], void>
259254
>;
260-
runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk], void>;
261-
seal: liteTapable.SyncHook<[], void>;
255+
runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk]>;
256+
seal: liteTapable.SyncHook<[]>;
262257
afterSeal: liteTapable.AsyncSeriesHook<[], void>;
263258
needAdditionalPass: liteTapable.SyncBailHook<[], boolean>;
264259
}>;
@@ -1237,9 +1232,7 @@ export class Entries implements Map<string, EntryData> {
12371232
return this.entries();
12381233
}
12391234

1240-
get [Symbol.toStringTag](): string {
1241-
return "Map";
1242-
}
1235+
readonly [Symbol.toStringTag] = "Map";
12431236

12441237
has(key: string): boolean {
12451238
return this.#data.has(key);

packages/rspack/src/config/devServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export type DevServerOptions<
302302
| ((
303303
req: Request,
304304
res: Response,
305-
context: DevMiddlewareContext<Request, Response> | undefined
305+
context: DevMiddlewareContext | undefined
306306
) => Headers)
307307
| undefined;
308308
onListening?: ((devServer: Server) => void) | undefined;

packages/rspack/src/loader-runner/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ export async function runLoaders(
727727
});
728728
Object.defineProperty(loaderContext, "cacheable", {
729729
enumerable: true,
730-
get: () => (cacheable: boolean) => {
730+
get: () => (cacheable?: boolean) => {
731731
if (cacheable === false) {
732732
context.cacheable = cacheable;
733733
}

packages/rspack/src/loader-runner/service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ export const run = async (
256256
}
257257
});
258258
mainPort.on("messageerror", handleError);
259+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
259260
mainSyncPort.on("message", async (message: WorkerRequestSyncMessage) => {
260-
const sharedBuffer = message.sharedBuffer;
261+
const { sharedBuffer } = message;
261262
const sharedBufferView = new Int32Array(sharedBuffer);
262263

263264
let result: any;

packages/rspack/src/loader-runner/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ async function loaderImpl(
406406
return options;
407407
};
408408

409-
loaderContext.cacheable = function cacheable(flag: boolean) {
409+
loaderContext.cacheable = function cacheable(flag?: boolean) {
410410
if (flag === false) {
411411
sendRequest(RequestType.SetCacheable, false);
412412
}

packages/rspack/src/stats/StatsPrinter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ export type StatsPrinterContext = KnownStatsPrinterContext &
5454
Record<string, any>;
5555

5656
export class StatsPrinter {
57-
private _levelHookCache: Map<
58-
HookMap<Hook<any, any>>,
59-
Map<string, Hook<any, any>[]>
60-
>;
57+
private _levelHookCache: Map<HookMap<Hook>, Map<string, Hook[]>>;
6158
private _inPrint: boolean;
6259

6360
hooks: Readonly<{
@@ -133,7 +130,7 @@ export class StatsPrinter {
133130
/**
134131
* get all level hooks
135132
*/
136-
private _getAllLevelHooks<T extends Hook<any, any>>(
133+
private _getAllLevelHooks<T extends Hook>(
137134
hookMap: HookMap<T>,
138135
type: string
139136
): T[] {

packages/rspack/src/util/SizeFormatHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
export const formatSize = (size: unknown) => {
12-
if (typeof size !== "number" || Number.isNaN(size) === true) {
12+
if (typeof size !== "number" || Number.isNaN(size)) {
1313
return "unknown size";
1414
}
1515

packages/rspack/src/util/fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ export type IntermediateFileSystemExtras = {
566566
arg2: (arg0: null | NodeJS.ErrnoException) => void
567567
) => void;
568568
mkdirSync: MkdirSync;
569-
write: Write<Buffer>;
569+
write: Write;
570570
open: Open;
571-
read: Read<Buffer>;
571+
read: Read;
572572
close: (
573573
arg0: number,
574574
arg1: (arg0: null | NodeJS.ErrnoException) => void

0 commit comments

Comments
 (0)