Skip to content

Commit 08bba62

Browse files
committed
chore: add Rslint
1 parent 477004d commit 08bba62

File tree

14 files changed

+145
-38
lines changed

14 files changed

+145
-38
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"check-spell": "pnpx cspell && heading-case",
1111
"format": "prettier . --write && biome check --write && heading-case --write",
1212
"generate-release-pr": "zx scripts/generateReleasePr.mjs",
13-
"lint": "biome check . --diagnostic-level=warn && prettier . --check && pnpm run check-spell",
13+
"lint": "biome check . --diagnostic-level=warn && prettier . --check && pnpm run check-spell && pnpm lint:type",
14+
"lint:type": "rslint",
1415
"prebundle": "nx run-many -t prebundle",
1516
"prepare": "pnpm run build && simple-git-hooks",
1617
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
@@ -42,6 +43,7 @@
4243
"devDependencies": {
4344
"@biomejs/biome": "^2.1.3",
4445
"@changesets/cli": "^2.29.5",
46+
"@rslint/core": "^0.1.5",
4547
"@rstest/core": "0.1.1",
4648
"@types/fs-extra": "^11.0.4",
4749
"@types/node": "^22.17.0",

packages/core/src/cli/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export function prepareCli(): void {
2323
console.log();
2424
}
2525

26-
logger.greet(` ${`Rslib v${RSLIB_VERSION}`}\n`);
26+
logger.greet(` Rslib v${RSLIB_VERSION}\n`);
2727
}

packages/core/src/config.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ const composeExternalsWarnConfig = (
218218
asyncFlag = false;
219219
return;
220220
}
221-
return next();
221+
next();
222+
return;
222223
}
223224

224225
callback(matched, shouldWarn);
@@ -227,7 +228,8 @@ const composeExternalsWarnConfig = (
227228
do {
228229
asyncFlag = true;
229230
if (i >= externals.length) {
230-
return callback(false);
231+
callback(false);
232+
return;
231233
}
232234
matchUserExternals(
233235
externals[i++],
@@ -308,7 +310,7 @@ export const composeAutoExternalConfig = (options: {
308310
const { bundle, format, pkgJson, userExternals } = options;
309311

310312
// If bundle is false, autoExternal will be disabled
311-
if (bundle === false) {
313+
if (!bundle) {
312314
return {};
313315
}
314316

@@ -352,7 +354,7 @@ export const composeAutoExternalConfig = (options: {
352354
)
353355
.reduce<string[]>((prev, type) => {
354356
if (externalOptions[type]) {
355-
return pkgJson[type] ? prev.concat(Object.keys(pkgJson[type]!)) : prev;
357+
return pkgJson[type] ? prev.concat(Object.keys(pkgJson[type])) : prev;
356358
}
357359
return prev;
358360
}, [])
@@ -648,7 +650,7 @@ const composeFormatConfig = ({
648650
},
649651
};
650652
case 'umd': {
651-
if (bundle === false) {
653+
if (!bundle) {
652654
throw new Error(
653655
'When using "umd" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.',
654656
);
@@ -686,7 +688,7 @@ const composeFormatConfig = ({
686688
return config;
687689
}
688690
case 'iife': {
689-
if (bundle === false) {
691+
if (!bundle) {
690692
throw new Error(
691693
'When using "iife" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.',
692694
);
@@ -729,7 +731,7 @@ const composeFormatConfig = ({
729731
return config;
730732
}
731733
case 'mf':
732-
if (bundle === false) {
734+
if (!bundle) {
733735
throw new Error(
734736
'When using "mf" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.',
735737
);
@@ -743,7 +745,7 @@ const composeFormatConfig = ({
743745
rspack: (config, { env }) => {
744746
config.output = {
745747
...config.output,
746-
uniqueName: pkgJson.name as string,
748+
uniqueName: pkgJson.name,
747749
};
748750

749751
config.optimization = {
@@ -1086,7 +1088,7 @@ const composeEntryConfig = async (
10861088
} else {
10871089
// Non-existed file.
10881090
entryErrorReasons.push(
1089-
`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(`${entryAbsPath}`)}. Please ensure that the file exists.`,
1091+
`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(entryAbsPath)}. Please ensure that the file exists.`,
10901092
);
10911093
}
10921094
}
@@ -1253,12 +1255,13 @@ const composeBundlelessExternalConfig = (
12531255
async (data, callback) => {
12541256
const { request, getResolve, context, contextInfo } = data;
12551257
if (!request || !getResolve || !context || !contextInfo) {
1256-
return callback();
1258+
callback();
1259+
return;
12571260
}
12581261
const { issuer } = contextInfo;
12591262

12601263
if (!resolver) {
1261-
resolver = (await getResolve()) as RspackResolver;
1264+
resolver = getResolve() as RspackResolver;
12621265
}
12631266

12641267
async function redirectPath(
@@ -1327,7 +1330,8 @@ const composeBundlelessExternalConfig = (
13271330
}
13281331

13291332
if (redirectedPath === undefined) {
1330-
return callback(undefined, request);
1333+
callback(undefined, request);
1334+
return;
13311335
}
13321336

13331337
if (jsRedirectPath) {
@@ -1374,7 +1378,8 @@ const composeBundlelessExternalConfig = (
13741378
}
13751379
}
13761380

1377-
return callback(undefined, resolvedRequest);
1381+
callback(undefined, resolvedRequest);
1382+
return;
13781383
}
13791384

13801385
callback();

packages/core/src/css/cssConfig.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function cssExternalHandler(
2626
// cssExtract: do not external @rsbuild/core/compiled/css-loader/noSourceMaps.js, sourceMaps.js, api.mjs etc.
2727
// cssExtract would execute the result handled by css-loader with importModule, so we cannot external the "helper import" from css-loader
2828
if (/compiled\/css-loader\//.test(request)) {
29-
return callback();
29+
callback();; return;
3030
}
3131

3232
let resolvedRequest = request;
@@ -41,7 +41,7 @@ export async function cssExternalHandler(
4141
if (!isCssFile(resolvedRequest)) {
4242
// cssExtract: do not external assets module import
4343
if (isCssFile(issuer)) {
44-
return callback();
44+
callback();; return;
4545
}
4646
return false;
4747
}
@@ -51,15 +51,15 @@ export async function cssExternalHandler(
5151
if (styleRedirectExtension) {
5252
const isCssModulesRequest = isCssModulesFile(resolvedRequest, auto);
5353
if (isCssModulesRequest) {
54-
return callback(
54+
callback(
5555
undefined,
5656
resolvedRequest.replace(/\.[^.]+$/, jsExtension),
57-
);
57+
);; return;
5858
}
59-
return callback(undefined, resolvedRequest.replace(/\.[^.]+$/, '.css'));
59+
callback(undefined, resolvedRequest.replace(/\.[^.]+$/, '.css'));; return;
6060
}
6161

62-
return callback(undefined, resolvedRequest);
62+
callback(undefined, resolvedRequest);
6363
}
6464

6565
const PLUGIN_NAME = 'rsbuild:lib-css';

packages/core/src/css/libCssExtractLoader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
9595
const banner = options.banner;
9696
const footer = options.footer;
9797

98-
let { publicPath } = this._compilation!.outputOptions;
98+
let { publicPath } = this._compilation.outputOptions;
9999

100100
if (typeof options.publicPath === 'string') {
101101
// eslint-disable-next-line prefer-destructuring
@@ -213,7 +213,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
213213
const localsString = identifiers
214214
.map(
215215
([id, key]) =>
216-
`\nvar ${id} = ${stringifyLocal(locals![key as string])};`,
216+
`\nvar ${id} = ${stringifyLocal(locals[key!])};`,
217217
)
218218
.join('');
219219
const exportsString = `export { ${identifiers
@@ -282,7 +282,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
282282
}
283283
if (sourceMap) {
284284
const sourceMapPath = `${distFilepath}.map`;
285-
m.set(sourceMapPath, `${sourceMap}`);
285+
m.set(sourceMapPath, sourceMap);
286286
// Associate the source map with the CSS file
287287
const sourceMappingURL = `/*# sourceMappingURL=${cssFilename}.map */`;
288288
m.set(distFilepath, `${m.get(distFilepath)}\n${sourceMappingURL}`);

packages/core/src/utils/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { logger } from './logger';
1111
* Node.js built-in modules.
1212
* Copied from https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L12-L72
1313
*/
14-
export const nodeBuiltInModules: Array<string | RegExp> = [
14+
export const nodeBuiltInModules: (string | RegExp)[] = [
1515
'assert',
1616
'assert/strict',
1717
'async_hooks',
@@ -140,7 +140,7 @@ export const isEmptyObject = (obj: object): boolean => {
140140

141141
export function pick<T, U extends keyof T>(
142142
obj: T,
143-
keys: ReadonlyArray<U>,
143+
keys: readonly U[],
144144
): Pick<T, U> {
145145
return keys.reduce(
146146
(ret, key) => {

packages/core/src/utils/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ logger.override({
4343
if (logger.level !== 'verbose') {
4444
return;
4545
}
46-
const time = color.gray(`${getTime()}`);
46+
const time = color.gray(getTime());
4747
console.log(` ${color.green('rslib')} ${time} ${message}`, ...args);
4848
},
4949
});

packages/plugin-dts/src/apiExtractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
3232
throw error;
3333
}
3434

35-
const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor!;
35+
const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor;
3636
const {
3737
name,
3838
cwd,
@@ -53,7 +53,7 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
5353
relative(cwd, distPath),
5454
`${entry.name}${dtsExtension}`,
5555
);
56-
const mainEntryPointFilePath = entry.path!.replace(/\?.*$/, '')!;
56+
const mainEntryPointFilePath = entry.path!.replace(/\?.*$/, '');
5757
const internalConfig = {
5858
mainEntryPointFilePath,
5959
bundledPackages,

packages/plugin-dts/src/dts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
194194
: dtsEmitPath;
195195

196196
let dtsEntries: Required<DtsEntry>[] = [];
197-
if (bundle === true) {
197+
if (bundle) {
198198
dtsEntries = dtsEntry
199199
.map((entryObj) => {
200200
const { name: entryName, path: entryPath } = entryObj;
@@ -204,7 +204,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
204204
: join(cwd, entryPath);
205205
const relativePath = relative(rootDir, dirname(entrySourcePath));
206206
const newPath = join(
207-
declarationDir!,
207+
declarationDir,
208208
relativePath,
209209
basename(entrySourcePath),
210210
).replace(
@@ -217,7 +217,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
217217
}
218218

219219
const bundleDtsIfNeeded = async () => {
220-
if (bundle === true) {
220+
if (bundle) {
221221
const { bundleDts } = await import('./apiExtractor');
222222
await bundleDts({
223223
name,

packages/plugin-dts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
114114
const cwd = api.context.rootPath;
115115
const tsconfigPath = ts.findConfigFile(
116116
cwd,
117-
ts.sys.fileExists,
117+
ts.sys.fileExists.bind(ts.sys),
118118
config.source.tsconfigPath,
119119
);
120120

0 commit comments

Comments
 (0)