Skip to content

Commit 66c575c

Browse files
authored
chore: integrate Rslint for type-aware linting (#1151)
1 parent bf45cf6 commit 66c575c

File tree

20 files changed

+154
-42
lines changed

20 files changed

+154
-42
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Rstack is a unified JavaScript toolchain built around Rspack, with high performa
5757
| [Rspress](https://github.com/web-infra-dev/rspress) | Static site generator |
5858
| [Rsdoctor](https://github.com/web-infra-dev/rsdoctor) | Build analyzer |
5959
| [Rstest](https://github.com/web-infra-dev/rstest) | Testing framework |
60+
| [Rslint](https://github.com/web-infra-dev/rslint) | Linter |
6061

6162
## 🔗 Links
6263

README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Rstack 是一个围绕 Rspack 打造的 JavaScript 统一工具链,具有优
5757
| [Rspress](https://github.com/web-infra-dev/rspress) | 静态站点生成器 |
5858
| [Rsdoctor](https://github.com/web-infra-dev/rsdoctor) | 构建分析工具 |
5959
| [Rstest](https://github.com/web-infra-dev/rstest) | 测试框架 |
60+
| [Rslint](https://github.com/web-infra-dev/rslint) | 代码检查工具 |
6061

6162
## 🔗 链接
6263

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.1.3/schema.json",
33
"assist": {
44
"actions": {
55
"source": {

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
}, [])
@@ -654,7 +656,7 @@ const composeFormatConfig = ({
654656
},
655657
};
656658
case 'umd': {
657-
if (bundle === false) {
659+
if (!bundle) {
658660
throw new Error(
659661
'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.',
660662
);
@@ -692,7 +694,7 @@ const composeFormatConfig = ({
692694
return config;
693695
}
694696
case 'iife': {
695-
if (bundle === false) {
697+
if (!bundle) {
696698
throw new Error(
697699
'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.',
698700
);
@@ -735,7 +737,7 @@ const composeFormatConfig = ({
735737
return config;
736738
}
737739
case 'mf':
738-
if (bundle === false) {
740+
if (!bundle) {
739741
throw new Error(
740742
'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.',
741743
);
@@ -749,7 +751,7 @@ const composeFormatConfig = ({
749751
rspack: (config, { env }) => {
750752
config.output = {
751753
...config.output,
752-
uniqueName: pkgJson.name as string,
754+
uniqueName: pkgJson.name,
753755
};
754756

755757
config.optimization = {
@@ -1092,7 +1094,7 @@ const composeEntryConfig = async (
10921094
} else {
10931095
// Non-existed file.
10941096
entryErrorReasons.push(
1095-
`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(`${entryAbsPath}`)}. Please ensure that the file exists.`,
1097+
`Can't resolve the entry ${color.cyan(`"${entry}"`)} at the location ${color.cyan(entryAbsPath)}. Please ensure that the file exists.`,
10961098
);
10971099
}
10981100
}
@@ -1259,12 +1261,13 @@ const composeBundlelessExternalConfig = (
12591261
async (data, callback) => {
12601262
const { request, getResolve, context, contextInfo } = data;
12611263
if (!request || !getResolve || !context || !contextInfo) {
1262-
return callback();
1264+
callback();
1265+
return;
12631266
}
12641267
const { issuer } = contextInfo;
12651268

12661269
if (!resolver) {
1267-
resolver = (await getResolve()) as RspackResolver;
1270+
resolver = getResolve() as RspackResolver;
12681271
}
12691272

12701273
async function redirectPath(
@@ -1333,7 +1336,8 @@ const composeBundlelessExternalConfig = (
13331336
}
13341337

13351338
if (redirectedPath === undefined) {
1336-
return callback(undefined, request);
1339+
callback(undefined, request);
1340+
return;
13371341
}
13381342

13391343
if (jsRedirectPath) {
@@ -1380,7 +1384,8 @@ const composeBundlelessExternalConfig = (
13801384
}
13811385
}
13821386

1383-
return callback(undefined, resolvedRequest);
1387+
callback(undefined, resolvedRequest);
1388+
return;
13841389
}
13851390

13861391
callback();

packages/core/src/css/cssConfig.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ 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();
30+
return;
3031
}
3132

3233
let resolvedRequest = request;
@@ -41,7 +42,8 @@ export async function cssExternalHandler(
4142
if (!isCssFile(resolvedRequest)) {
4243
// cssExtract: do not external assets module import
4344
if (isCssFile(issuer)) {
44-
return callback();
45+
callback();
46+
return;
4547
}
4648
return false;
4749
}
@@ -51,15 +53,14 @@ export async function cssExternalHandler(
5153
if (styleRedirectExtension) {
5254
const isCssModulesRequest = isCssModulesFile(resolvedRequest, auto);
5355
if (isCssModulesRequest) {
54-
return callback(
55-
undefined,
56-
resolvedRequest.replace(/\.[^.]+$/, jsExtension),
57-
);
56+
callback(undefined, resolvedRequest.replace(/\.[^.]+$/, jsExtension));
57+
return;
5858
}
59-
return callback(undefined, resolvedRequest.replace(/\.[^.]+$/, '.css'));
59+
callback(undefined, resolvedRequest.replace(/\.[^.]+$/, '.css'));
60+
return;
6061
}
6162

62-
return callback(undefined, resolvedRequest);
63+
callback(undefined, resolvedRequest);
6364
}
6465

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

packages/core/src/css/libCssExtractLoader.ts

Lines changed: 3 additions & 4 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
@@ -212,8 +212,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
212212

213213
const localsString = identifiers
214214
.map(
215-
([id, key]) =>
216-
`\nvar ${id} = ${stringifyLocal(locals![key as string])};`,
215+
([id, key]) => `\nvar ${id} = ${stringifyLocal(locals[key!])};`,
217216
)
218217
.join('');
219218
const exportsString = `export { ${identifiers
@@ -282,7 +281,7 @@ export const pitch: Rspack.LoaderDefinition['pitch'] = function (
282281
}
283282
if (sourceMap) {
284283
const sourceMapPath = `${distFilepath}.map`;
285-
m.set(sourceMapPath, `${sourceMap}`);
284+
m.set(sourceMapPath, sourceMap);
286285
// Associate the source map with the CSS file
287286
const sourceMappingURL = `/*# sourceMappingURL=${cssFilename}.map */`;
288287
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
});

0 commit comments

Comments
 (0)