Skip to content

Commit 049d02a

Browse files
committed
chore(infra/lint): use rslint recommended rules
1 parent 721822d commit 049d02a

6 files changed

Lines changed: 24 additions & 20 deletions

File tree

rslint.config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
import { defineConfig, ts } from '@rslint/core';
22

3-
export default defineConfig([
4-
ts.configs.recommended,
5-
{
6-
rules: {
7-
'@typescript-eslint/no-explicit-any': 'off',
8-
},
9-
},
10-
]);
3+
export default defineConfig([ts.configs.recommended]);

rstest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { fileURLToPath } from 'node:url';
21
import { withRslibConfig } from '@rstest/adapter-rslib';
32
import { defineConfig } from '@rstest/core';
43

src/applyMatcherReplacement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { snakeCase } from 'lodash-es';
22
import type { ApplyPathMatcherOptions, PathMatcher } from './types';
33
import { compilePathMatcherRegExp, splitPathString } from './utils';
44

5-
export function applyPathMatcher(
5+
function applyPathMatcher(
66
matcher: PathMatcher,
77
str: string,
88
options: ApplyPathMatcherOptions = {},
99
): string {
1010
const regex = compilePathMatcherRegExp(matcher.match);
11-
const replacer = (substring: string, ...args: any[]): string => {
11+
const replacer = (substring: string, ...args: unknown[]): string => {
1212
if (
1313
options.minPartials &&
1414
splitPathString(substring).length < options.minPartials

src/createSnapshotSerializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { replacePnpmInnerPath } from './pnpm';
1010
import type { PathMatcher, SnapshotSerializerOptions } from './types';
1111

1212
export interface SnapshotSerializer {
13-
serialize: (val: any) => string;
14-
test: (arg0: any) => boolean;
13+
serialize: (val: unknown) => string;
14+
test: (arg0: unknown) => boolean;
1515
}
1616

1717
export function createSnapshotSerializer(

src/normalize.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,32 @@ export const normalizeCodeToPosix = (code: string): string => {
1515
return code.replace(
1616
// windows absolute path
1717
// ignore http, https, file
18-
/(?<![a-zA-Z])([a-zA-Z]:[\\/]+)([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/]+)*/g,
18+
/(?<![a-zA-Z])([a-zA-Z]:[\\/]+)([-\u4e00-\u9fa5\w\s.()~!@#$%^&()[\]{}+=]+[\\/]+)*/g,
1919
(match: string, _diskName: string) => {
2020
return normalizePathToPosix(match.replace(/[\\]{2,}/g, '\\'));
2121
},
2222
);
2323
};
2424

25+
const ANSI_ESCAPE = String.raw`\u001b`;
26+
const ANSI_BOLD_COLOR_REGEXP = new RegExp(
27+
`${ANSI_ESCAPE}\\[1m${ANSI_ESCAPE}\\[([0-9;]*)m`,
28+
'g',
29+
);
30+
const ANSI_BOLD_REGEXP = new RegExp(`${ANSI_ESCAPE}\\[1m`, 'g');
31+
const ANSI_RESET_REGEXP = new RegExp(
32+
`${ANSI_ESCAPE}\\[39m${ANSI_ESCAPE}\\[22m`,
33+
'g',
34+
);
35+
const ANSI_COLOR_REGEXP = new RegExp(`${ANSI_ESCAPE}\\[([0-9;]*)m`, 'g');
36+
2537
export const normalizeCLR = (str: string): string => {
2638
return (
2739
str
28-
.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, '<CLR=$1,BOLD>')
29-
.replace(/\u001b\[1m/g, '<CLR=BOLD>')
30-
.replace(/\u001b\[39m\u001b\[22m/g, '</CLR>')
31-
.replace(/\u001b\[([0-9;]*)m/g, '<CLR=$1>')
40+
.replace(ANSI_BOLD_COLOR_REGEXP, '<CLR=$1,BOLD>')
41+
.replace(ANSI_BOLD_REGEXP, '<CLR=BOLD>')
42+
.replace(ANSI_RESET_REGEXP, '</CLR>')
43+
.replace(ANSI_COLOR_REGEXP, '<CLR=$1>')
3244
// CHANGE: The time unit display in Rspack is second
3345
// CHANGE2: avoid a bad case "./react/assets.svg" -> "./react/assetsXsvg"
3446
// modified based on https://github.com/webpack/webpack/blob/001cab14692eb9a833c6b56709edbab547e291a1/test/StatsTestCases.basictest.js#L199

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export type PathMatchExpression = string | RegExp;
1+
type PathMatchExpression = string | RegExp;
22

33
export interface PathMatcher {
44
match: PathMatchExpression;
5-
mark: string | ((substring: string, ...args: any[]) => string);
5+
mark: string | ((substring: string, ...args: unknown[]) => string);
66
}
77

88
export interface Features {

0 commit comments

Comments
 (0)