chore: more descriptive eslint error messages for restricted syntax

This commit is contained in:
Evan You 2024-04-15 16:06:33 +08:00
parent 2ae908d00c
commit b11dab99d1
No known key found for this signature in database
GPG Key ID: B9D421896CA450FB
2 changed files with 19 additions and 9 deletions

View File

@ -26,13 +26,23 @@ module.exports = {
'no-restricted-syntax': [
'error',
banConstEnum,
// since we target ES2015 for baseline support, we need to forbid object
// rest spread usage in destructure as it compiles into a verbose helper.
'ObjectPattern > RestElement',
// tsc compiles assignment spread into Object.assign() calls, but esbuild
// still generates verbose helpers, so spread assignment is also prohiboted
'ObjectExpression > SpreadElement',
'AwaitExpression',
{
selector: 'ObjectPattern > RestElement',
message:
'Our output target is ES2016, and object rest spread results in ' +
'verbose helpers and should be avoided.',
},
{
selector: 'ObjectExpression > SpreadElement',
message:
'esbuild transpiles object spread into very verbose inline helpers.\n' +
'Please use the `extend` helper from @vue/shared instead.',
},
{
selector: 'AwaitExpression',
message:
'Our output target is ES2016, so async/await syntax should be avoided.',
},
],
'sort-imports': ['error', { ignoreDeclarationSort: true }],

View File

@ -331,7 +331,7 @@ function createConfig(format, output, plugins = []) {
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
sourceMap: output.sourcemap,
minify: false,
target: isServerRenderer || isCJSBuild ? 'es2019' : 'es2015',
target: isServerRenderer || isCJSBuild ? 'es2019' : 'es2016',
define: resolveDefine(),
}),
...resolveNodePlugins(),
@ -367,7 +367,7 @@ function createMinifiedConfig(/** @type {PackageFormat} */ format) {
terser({
module: /^esm/.test(format),
compress: {
ecma: 2015,
ecma: 2016,
pure_getters: true,
},
safari10: true,