Skip to content

Commit c692d90

Browse files
authored
chore: fix lint issues (#196)
1 parent 42b59af commit c692d90

File tree

7 files changed

+36
-38
lines changed

7 files changed

+36
-38
lines changed

client-src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
* https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
99
*/
1010

11-
// @ts-expect-error: No type definitions available for '@rspack/core/hot/emitter.js'
1211
import { emitter as hotEmitter } from '@rspack/core/hot/emitter.js';
13-
// @ts-expect-error: No type definitions available for '@rspack/core/hot/log.js'
14-
import { log as webpackHotLog } from '@rspack/core/hot/log.js';
12+
import { log as rspackHotLog } from '@rspack/core/hot/log.js';
1513
import { createOverlay, formatProblem } from './overlay.js';
1614
import socket from './socket.js';
1715
import { defineProgressElement, isProgressSupported } from './progress.js';
@@ -191,7 +189,7 @@ if (typeof parsedResourceQuery.reconnect !== 'undefined') {
191189

192190
const setAllLogLevel = (level: LogLevel): void => {
193191
// This is needed because the HMR logger operate separately from dev server logger
194-
webpackHotLog.setLogLevel(
192+
rspackHotLog.setLogLevel(
195193
level === 'verbose' || level === 'log' ? 'info' : (level as LogLevel),
196194
);
197195
setLogLevel(level);

client-src/modules/logger/Logger.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,17 @@ import {
1616
type TimersMap,
1717
} from '../types.js';
1818

19-
const LOG_SYMBOL = Symbol('webpack logger raw log method');
20-
const TIMERS_SYMBOL = Symbol('webpack logger times');
21-
const TIMERS_AGGREGATES_SYMBOL = Symbol('webpack logger aggregated times');
19+
const LOG_SYMBOL = Symbol('rspack logger raw log method');
20+
const TIMERS_SYMBOL = Symbol('rspack logger times');
21+
const TIMERS_AGGREGATES_SYMBOL = Symbol('rspack logger aggregated times');
2222

23-
class WebpackLogger {
23+
class RspackLogger {
2424
private [LOG_SYMBOL]: (type: LogTypeEnum, args?: Args) => void;
2525
private [TIMERS_SYMBOL]: TimersMap = new Map();
2626
private [TIMERS_AGGREGATES_SYMBOL]: TimersMap = new Map();
27-
// @ts-ignore
28-
private getChildLogger: (name: string | (() => string)) => WebpackLogger;
2927

30-
constructor(
31-
log: (type: LogTypeEnum, args?: Args) => void,
32-
getChildLogger: (name: string | (() => string)) => WebpackLogger,
33-
) {
28+
constructor(log: (type: LogTypeEnum, args?: Args) => void) {
3429
this[LOG_SYMBOL] = log;
35-
this.getChildLogger = getChildLogger;
3630
}
3731

3832
error(...args: Args) {
@@ -101,7 +95,7 @@ class WebpackLogger {
10195
timeLog(label?: string) {
10296
const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
10397
if (!prev) {
104-
throw new Error(`No such label '${label}' for WebpackLogger.timeLog()`);
98+
throw new Error(`No such label '${label}' for RspackLogger.timeLog()`);
10599
}
106100
const time = process.hrtime(prev);
107101
this[LOG_SYMBOL](LogType.time, [label, ...time]);
@@ -110,7 +104,7 @@ class WebpackLogger {
110104
timeEnd(label?: string) {
111105
const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
112106
if (!prev) {
113-
throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
107+
throw new Error(`No such label '${label}' for RspackLogger.timeEnd()`);
114108
}
115109
const time = process.hrtime(prev);
116110
/** @type {TimersMap} */
@@ -122,7 +116,7 @@ class WebpackLogger {
122116
const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label);
123117
if (!prev) {
124118
throw new Error(
125-
`No such label '${label}' for WebpackLogger.timeAggregate()`,
119+
`No such label '${label}' for RspackLogger.timeAggregate()`,
126120
);
127121
}
128122
const time = process.hrtime(prev);
@@ -151,4 +145,4 @@ class WebpackLogger {
151145
}
152146
}
153147

154-
export { WebpackLogger as Logger };
148+
export { RspackLogger as Logger };

client-src/modules/logger/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import type { LoggerOptions } from '../types.js';
1515
/**
1616
* Client stub for tapable SyncBailHook
1717
*/
18-
function SyncBailHook() {
19-
return {
20-
call() {},
21-
};
18+
class SyncBailHook {
19+
constructor(_args?: string[]) {}
20+
21+
call(_origin?: string, _type?: string, _args?: unknown) {
22+
return undefined;
23+
}
2224
}
2325

2426
const currentDefaultLoggerOptions = {
@@ -35,17 +37,13 @@ const configureDefaultLogger = (options: LoggerOptions): void => {
3537
};
3638

3739
const getLogger = (name: string): Logger =>
38-
new Logger(
39-
(type, args) => {
40-
if (hooks.log.call(name, type, args) === undefined) {
41-
currentDefaultLogger(name, type, args);
42-
}
43-
},
44-
(childName) => getLogger(`${name}/${childName}`),
45-
);
40+
new Logger((type, args) => {
41+
if (hooks.log.call(name, type, args) === undefined) {
42+
currentDefaultLogger(name, type, args);
43+
}
44+
});
4645

4746
const hooks = {
48-
// @ts-ignore
4947
log: new SyncBailHook(['origin', 'type', 'args']),
5048
};
5149

client-src/rspack-hot.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module '@rspack/core/hot/emitter.js' {
2+
export const emitter: {
3+
emit(eventName: string, ...args: unknown[]): void;
4+
};
5+
}
6+
7+
declare module '@rspack/core/hot/log.js' {
8+
export const log: {
9+
setLogLevel(level: string | boolean): void;
10+
};
11+
}

client-src/utils/ansiHTML.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ export default function ansiHTML(text: string) {
138138
const ansiCodes: string[] = [];
139139
// Replace with markup.
140140
let ret = text.replace(
141-
//@ts-ignore TS1487 error
142-
/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g,
141+
/\x1b\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g,
143142
(m) => {
144143
const match = m.match(/(;?\d+)/g)?.map(normalizeSeq) as unknown as Match;
145144
Object.defineProperty(match, 'advance', {

src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ class Server<
11831183
#getClientTransport() {
11841184
let clientImplementation: string | undefined;
11851185
let clientImplementationFound = true;
1186-
let clientTransport =
1186+
const clientTransport =
11871187
typeof this.options.client === 'object' &&
11881188
this.options.client !== null &&
11891189
typeof this.options.client.webSocketTransport !== 'undefined'

tests/normalizeOptions.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ async function match(config: RspackOptions) {
112112
);
113113
await server.start();
114114
// it will break ci
115-
//@ts-ignore
116115
server.options.port = undefined;
117116
expect(server.options).toMatchSnapshot();
118117
await server.stop();
@@ -146,8 +145,7 @@ async function getAdditionEntries(
146145
// some hack for snapshot
147146
const value = Object.fromEntries(
148147
Object.entries(entries).map(([key, item]) => {
149-
// @ts-expect-error
150-
const replaced = item.import?.map((entry) => {
148+
const replaced = (item as { import?: string[] }).import?.map((entry) => {
151149
const array = entry
152150
.replace(/\\/g, '/')
153151
.replace(/port=\d+/g, '')

0 commit comments

Comments
 (0)