Skip to content

Commit 1408057

Browse files
committed
fix: improve error logs
1 parent 2d2cc16 commit 1408057

File tree

6 files changed

+25
-41
lines changed

6 files changed

+25
-41
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ When Rsbuild detects incompatible advanced syntax in the build artifacts, it wil
4141
The format of the error logs is as follows, including the source file, artifact location, error reason, and source code:
4242

4343
```bash
44-
error [Syntax Checker] Find some syntax that does not match "ecmaVersion <= 2015":
44+
error [@rsbuild/plugin-check-syntax] Find some syntax that does not match "ecmaVersion <= 2015":
4545

4646
Error 1
4747
source: /node_modules/foo/index.js:1:0
@@ -80,9 +80,9 @@ export default {
8080
8181
If a syntax error is detected, you can handle it in the following ways:
8282
83-
- If you want to downgrade this syntax to ensure good code compatibility, you can compile the corresponding module through the `source.include` config.
83+
- If you want to downgrade this syntax to ensure good code compatibility, you can compile the specified module through the `source.include` config.
8484
- If you don't want to downgrade the syntax, you can adjust the project's browserslist to match the syntax.
85-
- If you do not want to check the syntax of specific files, you can use the `checkSyntax.exclude` configuration to exclude the files to be checked.
85+
- If you don't want to check the syntax of specified files, you can use the `exclude` option to exclude the files to be checked.
8686
8787
## Options
8888

playground/rsbuild.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import path from 'node:path';
12
import { defineConfig } from '@rsbuild/core';
23
import { pluginCheckSyntax } from '../src';
34

45
export default defineConfig({
6+
source: {
7+
exclude: [path.resolve(__dirname, './src/test.js')],
8+
},
9+
output: {
10+
sourceMap: {
11+
js: 'source-map',
12+
},
13+
overrideBrowserslist: ['ie 11'],
14+
},
515
plugins: [pluginCheckSyntax()],
616
});

playground/src/index.css

Lines changed: 0 additions & 26 deletions
This file was deleted.

playground/src/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import './index.css';
1+
import { printLog } from './test';
22

3-
document.querySelector('#root').innerHTML = `
4-
<div class="content">
5-
<h1>Vanilla Rsbuild</h1>
6-
<p>Start building amazing things with Rsbuild.</p>
7-
</div>
8-
`;
3+
printLog();

playground/src/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const printLog = () => {
2+
const arr = [1, 2, 3, 4, [5, 6, [7, 8]]];
3+
console.log(arr, arr.flat());
4+
};

src/printErrors.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function printErrors(
1414
ecmaVersion: EcmaVersion,
1515
): void {
1616
if (errors.length === 0) {
17-
logger.success('The syntax check success.');
17+
logger.success('[@rsbuild/plugin-check-syntax] Syntax check passed.');
1818
return;
1919
}
2020

@@ -31,7 +31,7 @@ export function printErrors(
3131

3232
const expectedVersion = color.yellow(`ecmaVersion <= ${ecmaVersion}`);
3333
logger.error(
34-
`[Syntax Checker] Find some syntax that does not match "${expectedVersion}":\n`,
34+
`[@rsbuild/plugin-check-syntax] Find some syntax that does not match "${expectedVersion}":\n`,
3535
);
3636

3737
errs.forEach((err, index) => {
@@ -40,10 +40,11 @@ export function printErrors(
4040
});
4141

4242
throw new Error(
43-
`[Syntax Checker] The current build fails due to an incompatible syntax, which can be fixed in the following ways:
43+
`[@rsbuild/plugin-check-syntax] The current build fails due to an incompatible syntax, which can be fixed in the following ways:
4444
45-
- If you want to downgrade the syntax, you can compile the corresponding module through the \`source.include\` config.
46-
- If you don't want to downgrade the syntax, you can adjust the project's browserslist to match the syntax.`,
45+
- If you want to downgrade the syntax, you can compile the specified module through the \`source.include\` config.
46+
- If you don't want to downgrade the syntax, you can adjust the project's browserslist to match the syntax.
47+
- If you don't want to check the syntax of specified files, you can use the \`exclude\` option to exclude the files to be checked.`,
4748
);
4849
}
4950

0 commit comments

Comments
 (0)