Skip to content

Commit bfe6b45

Browse files
sxzzAlfred-SkybluePlumbiu
authored
style: update format & lint config (vuejs#9162)
Co-authored-by: 丶远方 <[email protected]> Co-authored-by: 三咲智子 Kevin Deng <[email protected]> Co-authored-by: Guo Xingjun <[email protected]>
1 parent baf0b76 commit bfe6b45

File tree

464 files changed

+12751
-12292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

464 files changed

+12751
-12292
lines changed

.eslintrc.cjs

+55-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
/* eslint-disable no-restricted-globals */
2-
1+
const { builtinModules } = require('node:module')
32
const DOMGlobals = ['window', 'document']
43
const NodeGlobals = ['module', 'require']
54

65
const banConstEnum = {
76
selector: 'TSEnumDeclaration[const=true]',
87
message:
9-
'Please use non-const enums. This project automatically inlines enums.'
8+
'Please use non-const enums. This project automatically inlines enums.',
109
}
1110

1211
/**
@@ -15,9 +14,9 @@ const banConstEnum = {
1514
module.exports = {
1615
parser: '@typescript-eslint/parser',
1716
parserOptions: {
18-
sourceType: 'module'
17+
sourceType: 'module',
1918
},
20-
plugins: ['jest'],
19+
plugins: ['jest', 'import', '@typescript-eslint'],
2120
rules: {
2221
'no-debugger': 'error',
2322
// most of the codebase are expected to be env agnostic
@@ -32,8 +31,27 @@ module.exports = {
3231
// tsc compiles assignment spread into Object.assign() calls, but esbuild
3332
// still generates verbose helpers, so spread assignment is also prohiboted
3433
'ObjectExpression > SpreadElement',
35-
'AwaitExpression'
36-
]
34+
'AwaitExpression',
35+
],
36+
'sort-imports': ['error', { ignoreDeclarationSort: true }],
37+
38+
'import/no-nodejs-modules': [
39+
'error',
40+
{ allow: builtinModules.map(mod => `node:${mod}`) },
41+
],
42+
// This rule enforces the preference for using '@ts-expect-error' comments in TypeScript
43+
// code to indicate intentional type errors, improving code clarity and maintainability.
44+
'@typescript-eslint/prefer-ts-expect-error': 'error',
45+
// Enforce the use of 'import type' for importing types
46+
'@typescript-eslint/consistent-type-imports': [
47+
'error',
48+
{
49+
fixStyle: 'inline-type-imports',
50+
disallowTypeAnnotations: false,
51+
},
52+
],
53+
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
54+
'@typescript-eslint/no-import-type-side-effects': 'error',
3755
},
3856
overrides: [
3957
// tests, no restrictions (runs in Node / jest with jsdom)
@@ -43,54 +61,66 @@ module.exports = {
4361
'no-restricted-globals': 'off',
4462
'no-restricted-syntax': 'off',
4563
'jest/no-disabled-tests': 'error',
46-
'jest/no-focused-tests': 'error'
47-
}
64+
'jest/no-focused-tests': 'error',
65+
},
4866
},
4967
// shared, may be used in any env
5068
{
51-
files: ['packages/shared/**'],
69+
files: ['packages/shared/**', '.eslintrc.cjs'],
5270
rules: {
53-
'no-restricted-globals': 'off'
54-
}
71+
'no-restricted-globals': 'off',
72+
},
5573
},
5674
// Packages targeting DOM
5775
{
5876
files: ['packages/{vue,vue-compat,runtime-dom}/**'],
5977
rules: {
60-
'no-restricted-globals': ['error', ...NodeGlobals]
61-
}
78+
'no-restricted-globals': ['error', ...NodeGlobals],
79+
},
6280
},
6381
// Packages targeting Node
6482
{
6583
files: ['packages/{compiler-sfc,compiler-ssr,server-renderer}/**'],
6684
rules: {
6785
'no-restricted-globals': ['error', ...DOMGlobals],
68-
'no-restricted-syntax': ['error', banConstEnum]
69-
}
86+
'no-restricted-syntax': ['error', banConstEnum],
87+
},
7088
},
7189
// Private package, browser only + no syntax restrictions
7290
{
7391
files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
7492
rules: {
7593
'no-restricted-globals': ['error', ...NodeGlobals],
76-
'no-restricted-syntax': ['error', banConstEnum]
77-
}
94+
'no-restricted-syntax': ['error', banConstEnum],
95+
},
7896
},
7997
// JavaScript files
8098
{
8199
files: ['*.js', '*.cjs'],
82100
rules: {
83101
// We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
84-
'no-unused-vars': ['error', { vars: 'all', args: 'none' }]
85-
}
102+
'no-unused-vars': ['error', { vars: 'all', args: 'none' }],
103+
},
86104
},
87105
// Node scripts
88106
{
89-
files: ['scripts/**', '*.{js,ts}', 'packages/**/index.js'],
107+
files: [
108+
'scripts/**',
109+
'./*.{js,ts}',
110+
'packages/*/*.js',
111+
'packages/vue/*/*.js',
112+
],
90113
rules: {
91114
'no-restricted-globals': 'off',
92-
'no-restricted-syntax': ['error', banConstEnum]
93-
}
94-
}
95-
]
115+
'no-restricted-syntax': ['error', banConstEnum],
116+
},
117+
},
118+
// Import nodejs modules in compiler-sfc
119+
{
120+
files: ['packages/compiler-sfc/src/**'],
121+
rules: {
122+
'import/no-nodejs-modules': ['error', { allow: builtinModules }],
123+
},
124+
},
125+
],
96126
}

.github/renovate.json5

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77
packageRules: [
88
{
99
depTypeList: ['peerDependencies'],
10-
enabled: false
10+
enabled: false,
1111
},
1212
{
1313
groupName: 'test',
1414
matchPackageNames: ['vitest', 'jsdom', 'puppeteer'],
15-
matchPackagePrefixes: ['@vitest']
15+
matchPackagePrefixes: ['@vitest'],
1616
},
1717
{
1818
groupName: 'playground',
1919
matchFileNames: [
2020
'packages/sfc-playground/package.json',
21-
'packages/template-explorer/package.json'
22-
]
21+
'packages/template-explorer/package.json',
22+
],
2323
},
2424
{
2525
groupName: 'compiler',
2626
matchPackageNames: ['magic-string'],
27-
matchPackagePrefixes: ['@babel', 'postcss']
27+
matchPackagePrefixes: ['@babel', 'postcss'],
2828
},
2929
{
3030
groupName: 'build',
3131
matchPackageNames: ['vite', 'terser'],
32-
matchPackagePrefixes: ['rollup', 'esbuild', '@rollup', '@vitejs']
32+
matchPackagePrefixes: ['rollup', 'esbuild', '@rollup', '@vitejs'],
3333
},
3434
{
3535
groupName: 'lint',
3636
matchPackageNames: ['simple-git-hooks', 'lint-staged'],
37-
matchPackagePrefixes: ['@typescript-eslint', 'eslint', 'prettier']
38-
}
37+
matchPackagePrefixes: ['@typescript-eslint', 'eslint', 'prettier'],
38+
},
3939
],
4040
ignoreDeps: [
4141
'vue',
@@ -45,6 +45,6 @@
4545
'typescript',
4646

4747
// ESM only
48-
'estree-walker'
49-
]
48+
'estree-walker',
49+
],
5050
}

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
dist
2+
*.md
3+
*.html
4+
pnpm-lock.yaml

.prettierrc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
semi: false
2-
singleQuote: true
3-
printWidth: 80
4-
trailingComma: 'none'
5-
arrowParens: 'avoid'
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"arrowParens": "avoid"
5+
}

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"console": "integratedTerminal",
2222
"sourceMaps": true,
2323
"windows": {
24-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
24+
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
2525
}
2626
}
2727
]

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"size-esm-runtime": "node scripts/build.js vue -f esm-bundler-runtime",
1414
"size-esm": "node scripts/build.js runtime-dom runtime-core reactivity shared -f esm-bundler",
1515
"check": "tsc --incremental --noEmit",
16-
"lint": "eslint --cache --ext .ts packages/*/{src,__tests__}/**.ts",
17-
"format": "prettier --write --cache \"**/*.[tj]s?(x)\"",
18-
"format-check": "prettier --check --cache \"**/*.[tj]s?(x)\"",
16+
"lint": "eslint --cache --ext .js,.ts,.tsx .",
17+
"format": "prettier --write --cache .",
18+
"format-check": "prettier --check --cache .",
1919
"test": "vitest",
2020
"test-unit": "vitest -c vitest.unit.config.ts",
2121
"test-e2e": "node scripts/build.js vue -f global -d && vitest -c vitest.e2e.config.ts",
@@ -72,6 +72,7 @@
7272
"@types/minimist": "^1.2.5",
7373
"@types/node": "^20.10.5",
7474
"@types/semver": "^7.5.5",
75+
"@typescript-eslint/eslint-plugin": "^6.16.0",
7576
"@typescript-eslint/parser": "^6.15.0",
7677
"@vitest/coverage-istanbul": "^1.1.0",
7778
"@vue/consolidate": "0.17.3",
@@ -81,6 +82,7 @@
8182
"esbuild-plugin-polyfill-node": "^0.3.0",
8283
"eslint": "^8.56.0",
8384
"eslint-define-config": "^1.24.1",
85+
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
8486
"eslint-plugin-jest": "^27.6.0",
8587
"estree-walker": "^2.0.2",
8688
"execa": "^8.0.1",

0 commit comments

Comments
 (0)