Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c1355234c0 | ||
|
6dfc773b05 | ||
|
2bf0c8d727 | ||
|
504de8392a | ||
|
6cf4794985 | ||
|
bbed70b969 | ||
|
f553c519f6 | ||
|
4e77637da4 | ||
|
abf5c27385 | ||
|
7b48da27dc | ||
|
0947ddb151 | ||
|
0a9c9b0384 | ||
|
84ae087ea0 | ||
|
5d908028ca | ||
|
610d886afd | ||
|
aefa76e48a | ||
|
e787e9a647 | ||
|
a3598d36d2 | ||
|
7b399a63db | ||
|
bb09e1d6b4 | ||
|
f97f7ef7de | ||
|
0a19d26da6 | ||
|
ec494867f9 | ||
|
656f91ae61 | ||
|
cdb02c8fa1 | ||
|
3f2f335e42 | ||
|
3ca0e7ea8b | ||
|
96dd9a1797 | ||
|
2db56ec8f0 | ||
|
6503a153d8 | ||
|
10306427d9 | ||
|
e6cb79994e | ||
|
a602eb1b4f | ||
|
9114acddf6 | ||
|
e8cec1e2d5 | ||
|
506d17c3f7 | ||
|
ff74d69719 | ||
|
e28861a247 | ||
|
9fde0f404f | ||
|
78b405f91a | ||
|
ebb96c422e | ||
|
5240f68454 | ||
|
79c8de557e | ||
|
3f13db706b | ||
|
7a5daf6f38 | ||
|
79b63bc0c9 | ||
|
60002c33fd | ||
|
502f6b0c37 | ||
|
d1cd722857 | ||
|
d2150eec3b | ||
|
d3c3e1b84d | ||
|
3963633712 | ||
|
e9193343e8 |
1
.npmrc
1
.npmrc
@@ -1 +1,2 @@
|
|||||||
strict-peer-dependencies=false
|
strict-peer-dependencies=false
|
||||||
|
shamefully-hoist=true
|
||||||
|
30
README.md
30
README.md
@@ -41,23 +41,43 @@ For example:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Config VS Code auto fix
|
### VS Code support (auto fix)
|
||||||
|
|
||||||
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and create `.vscode/settings.json`
|
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
||||||
|
|
||||||
```json
|
Add the following settings to your `settings.json`:
|
||||||
|
|
||||||
|
```jsonc
|
||||||
{
|
{
|
||||||
"prettier.enable": false,
|
"prettier.enable": false,
|
||||||
"editor.formatOnSave": false,
|
"editor.formatOnSave": false,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": true,
|
||||||
|
"source.organizeImports": false,
|
||||||
|
|
||||||
|
// The following is optional.
|
||||||
|
// It's better to put under project setting `.vscode/settings.json`
|
||||||
|
// to avoid conflicts with working with different eslint configs
|
||||||
|
// that does not support all formats.
|
||||||
|
"eslint.validate": [
|
||||||
|
"javascript",
|
||||||
|
"javascriptreact",
|
||||||
|
"typescript",
|
||||||
|
"typescriptreact",
|
||||||
|
"vue",
|
||||||
|
"html",
|
||||||
|
"markdown",
|
||||||
|
"json",
|
||||||
|
"jsonc",
|
||||||
|
"yaml"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### TypeScript Aware Rules
|
### TypeScript Aware Rules
|
||||||
|
|
||||||
Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
|
Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// .eslintrc.js
|
// .eslintrc.js
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@8.0.0",
|
"packageManager": "pnpm@8.5.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite-ssg build",
|
"build": "vite-ssg build",
|
||||||
"dev": "vite --port 3333 --open",
|
"dev": "vite --port 3333 --open",
|
||||||
@@ -15,48 +15,48 @@
|
|||||||
"up": "taze major -I"
|
"up": "taze major -I"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@unocss/reset": "^0.50.6",
|
"@unocss/reset": "^0.52.1",
|
||||||
"@vueuse/core": "^9.13.0",
|
"@vueuse/core": "^10.1.2",
|
||||||
"@vueuse/head": "^1.1.23",
|
"@vueuse/head": "^1.1.26",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"pinia": "^2.0.33",
|
"pinia": "^2.1.3",
|
||||||
"vue": "^3.2.47",
|
"vue": "^3.3.4",
|
||||||
"vue-demi": "^0.13.11",
|
"vue-demi": "^0.14.5",
|
||||||
"vue-i18n": "^9.2.2",
|
"vue-i18n": "^9.2.2",
|
||||||
"vue-router": "^4.1.6"
|
"vue-router": "^4.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^0.37.0",
|
"@antfu/eslint-config": "^0.39.1",
|
||||||
"@iconify-json/carbon": "^1.1.16",
|
"@iconify-json/carbon": "^1.1.16",
|
||||||
"@intlify/vite-plugin-vue-i18n": "^7.0.0",
|
"@intlify/vite-plugin-vue-i18n": "^7.0.0",
|
||||||
"@types/markdown-it-link-attributes": "^3.0.1",
|
"@types/markdown-it-link-attributes": "^3.0.1",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
"@vitejs/plugin-vue": "^4.1.0",
|
"@vitejs/plugin-vue": "^4.2.3",
|
||||||
"@vue/test-utils": "^2.3.2",
|
"@vue/test-utils": "^2.3.2",
|
||||||
"critters": "^0.0.16",
|
"critters": "^0.0.16",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"cypress": "^12.9.0",
|
"cypress": "^12.12.0",
|
||||||
"eslint": "^8.37.0",
|
"eslint": "^8.41.0",
|
||||||
"eslint-plugin-cypress": "^2.13.2",
|
"eslint-plugin-cypress": "^2.13.3",
|
||||||
"https-localhost": "^4.7.1",
|
"https-localhost": "^4.7.1",
|
||||||
"markdown-it-link-attributes": "^4.0.1",
|
"markdown-it-link-attributes": "^4.0.1",
|
||||||
"markdown-it-shiki": "^0.8.0",
|
"markdown-it-shiki": "^0.9.0",
|
||||||
"pnpm": "^8.0.0",
|
"pnpm": "^8.5.1",
|
||||||
"shiki": "^0.14.1",
|
"shiki": "^0.14.2",
|
||||||
"taze": "^0.9.1",
|
"taze": "^0.10.1",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.0.4",
|
||||||
"unocss": "^0.50.6",
|
"unocss": "^0.52.1",
|
||||||
"unplugin-auto-import": "^0.15.2",
|
"unplugin-auto-import": "^0.16.2",
|
||||||
"unplugin-vue-components": "^0.24.1",
|
"unplugin-vue-components": "^0.24.1",
|
||||||
"vite": "^4.2.1",
|
"vite": "^4.3.8",
|
||||||
"vite-plugin-inspect": "^0.7.18",
|
"vite-plugin-inspect": "^0.7.26",
|
||||||
"vite-plugin-pages": "^0.29.0",
|
"vite-plugin-pages": "^0.30.1",
|
||||||
"vite-plugin-pwa": "^0.14.7",
|
"vite-plugin-pwa": "^0.15.0",
|
||||||
"vite-plugin-vue-layouts": "^0.8.0",
|
"vite-plugin-vue-layouts": "^0.8.0",
|
||||||
"vite-plugin-vue-markdown": "^0.22.4",
|
"vite-plugin-vue-markdown": "^0.23.5",
|
||||||
"vite-ssg": "^0.22.1",
|
"vite-ssg": "^0.22.2",
|
||||||
"vite-ssg-sitemap": "^0.4.3",
|
"vite-ssg-sitemap": "^0.5.1",
|
||||||
"vitest": "^0.29.8",
|
"vitest": "^0.31.1",
|
||||||
"vue-tsc": "^1.2.0"
|
"vue-tsc": "^1.6.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
package.json
17
package.json
@@ -1,22 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-monorepo",
|
"name": "@antfu/eslint-config-monorepo",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@8.0.0",
|
"packageManager": "pnpm@8.5.1",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "pnpm -r run stub && eslint .",
|
||||||
"test": "pnpm -r run test",
|
"test": "pnpm -r run test",
|
||||||
|
"build": "pnpm -r run build",
|
||||||
"prepare": "pnpm -r run stub",
|
"prepare": "pnpm -r run stub",
|
||||||
"release": "bumpp -r && pnpm -r publish"
|
"release": "bumpp -r && pnpm -r publish"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "workspace:*",
|
"@antfu/eslint-config": "workspace:*",
|
||||||
"bumpp": "^9.0.0",
|
"bumpp": "^9.1.0",
|
||||||
"eslint": "^8.37.0",
|
"eslint": "^8.41.0",
|
||||||
"eslint-plugin-antfu": "workspace:*",
|
"eslint-plugin-antfu": "link:./packages/eslint-plugin-antfu",
|
||||||
"rimraf": "^4.4.1",
|
"rimraf": "^5.0.1",
|
||||||
"typescript": "^5.0.2"
|
"typescript": "^5.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,8 @@ module.exports = {
|
|||||||
'!.github',
|
'!.github',
|
||||||
'!.vitepress',
|
'!.vitepress',
|
||||||
'!.vscode',
|
'!.vscode',
|
||||||
|
// force exclude
|
||||||
|
'.vitepress/cache',
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
'html',
|
'html',
|
||||||
@@ -57,7 +59,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
files: ['*.json', '*.json5'],
|
files: ['*.json', '*.json5', '*.jsonc'],
|
||||||
parser: 'jsonc-eslint-parser',
|
parser: 'jsonc-eslint-parser',
|
||||||
rules: {
|
rules: {
|
||||||
'jsonc/array-bracket-spacing': ['error', 'never'],
|
'jsonc/array-bracket-spacing': ['error', 'never'],
|
||||||
@@ -154,9 +156,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
files: ['*.js', '*.cjs'],
|
files: ['*.js', '*.cjs', '*.jsx'],
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-var-requires': 'off',
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
|
'@typescript-eslint/no-require-imports': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -188,6 +191,8 @@ module.exports = {
|
|||||||
'@typescript-eslint/no-var-requires': 'off',
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
'@typescript-eslint/comma-dangle': 'off',
|
'@typescript-eslint/comma-dangle': 'off',
|
||||||
'@typescript-eslint/consistent-type-imports': 'off',
|
'@typescript-eslint/consistent-type-imports': 'off',
|
||||||
|
'@typescript-eslint/no-namespace': 'off',
|
||||||
|
'@typescript-eslint/no-require-imports': 'off',
|
||||||
'import/no-unresolved': 'off',
|
'import/no-unresolved': 'off',
|
||||||
'unused-imports/no-unused-imports': 'off',
|
'unused-imports/no-unused-imports': 'off',
|
||||||
'unused-imports/no-unused-vars': 'off',
|
'unused-imports/no-unused-vars': 'off',
|
||||||
@@ -197,6 +202,8 @@ module.exports = {
|
|||||||
'no-undef': 'off',
|
'no-undef': 'off',
|
||||||
'no-unused-expressions': 'off',
|
'no-unused-expressions': 'off',
|
||||||
'no-unused-vars': 'off',
|
'no-unused-vars': 'off',
|
||||||
|
'antfu/no-cjs-exports': 'off',
|
||||||
|
'antfu/no-ts-export-equal': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -207,6 +214,7 @@ module.exports = {
|
|||||||
'import/no-mutable-exports': 'error',
|
'import/no-mutable-exports': 'error',
|
||||||
'import/no-unresolved': 'off',
|
'import/no-unresolved': 'off',
|
||||||
'import/no-absolute-path': 'off',
|
'import/no-absolute-path': 'off',
|
||||||
|
'import/newline-after-import': ['error', { count: 1, considerComments: true }],
|
||||||
|
|
||||||
// Common
|
// Common
|
||||||
'semi': ['error', 'never'],
|
'semi': ['error', 'never'],
|
||||||
@@ -232,7 +240,7 @@ module.exports = {
|
|||||||
'no-debugger': 'error',
|
'no-debugger': 'error',
|
||||||
'no-console': ['error', { allow: ['warn', 'error'] }],
|
'no-console': ['error', { allow: ['warn', 'error'] }],
|
||||||
'no-cond-assign': ['error', 'always'],
|
'no-cond-assign': ['error', 'always'],
|
||||||
'func-call-spacing': ['off', 'never'],
|
'func-call-spacing': 'off',
|
||||||
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
||||||
'indent': ['error', 2, { SwitchCase: 1, VariableDeclarator: 1, outerIIFEBody: 1 }],
|
'indent': ['error', 2, { SwitchCase: 1, VariableDeclarator: 1, outerIIFEBody: 1 }],
|
||||||
'no-restricted-syntax': [
|
'no-restricted-syntax': [
|
||||||
@@ -251,6 +259,19 @@ module.exports = {
|
|||||||
asyncArrow: 'always',
|
asyncArrow: 'always',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
'no-restricted-globals': [
|
||||||
|
'error',
|
||||||
|
{ name: 'global', message: 'Use `globalThis` instead.' },
|
||||||
|
{ name: 'self', message: 'Use `globalThis` instead.' },
|
||||||
|
],
|
||||||
|
'no-restricted-properties': [
|
||||||
|
'error',
|
||||||
|
{ property: '__proto__', message: 'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.' },
|
||||||
|
{ property: '__defineGetter__', message: 'Use `Object.defineProperty` instead.' },
|
||||||
|
{ property: '__defineSetter__', message: 'Use `Object.defineProperty` instead.' },
|
||||||
|
{ property: '__lookupGetter__', message: 'Use `Object.getOwnPropertyDescriptor` instead.' },
|
||||||
|
{ property: '__lookupSetter__', message: 'Use `Object.getOwnPropertyDescriptor` instead.' },
|
||||||
|
],
|
||||||
|
|
||||||
// es6
|
// es6
|
||||||
'no-var': 'error',
|
'no-var': 'error',
|
||||||
@@ -299,7 +320,7 @@ module.exports = {
|
|||||||
'array-callback-return': 'error',
|
'array-callback-return': 'error',
|
||||||
'block-scoped-var': 'error',
|
'block-scoped-var': 'error',
|
||||||
'consistent-return': 'off',
|
'consistent-return': 'off',
|
||||||
'complexity': ['off', 11],
|
'complexity': 'off',
|
||||||
'eqeqeq': ['error', 'smart'],
|
'eqeqeq': ['error', 'smart'],
|
||||||
'no-alert': 'warn',
|
'no-alert': 'warn',
|
||||||
'no-case-declarations': 'error',
|
'no-case-declarations': 'error',
|
||||||
@@ -308,12 +329,18 @@ module.exports = {
|
|||||||
'no-with': 'error',
|
'no-with': 'error',
|
||||||
'no-void': 'error',
|
'no-void': 'error',
|
||||||
'no-useless-escape': 'off',
|
'no-useless-escape': 'off',
|
||||||
|
'no-invalid-this': 'error',
|
||||||
'vars-on-top': 'error',
|
'vars-on-top': 'error',
|
||||||
'require-await': 'off',
|
'require-await': 'off',
|
||||||
'no-return-assign': 'off',
|
'no-return-assign': 'off',
|
||||||
'operator-linebreak': ['error', 'before'],
|
'operator-linebreak': ['error', 'before'],
|
||||||
'max-statements-per-line': ['error', { max: 1 }],
|
'max-statements-per-line': ['error', { max: 1 }],
|
||||||
|
|
||||||
|
// node
|
||||||
|
// 'n/prefer-global/process': ['error', 'never'], // Not sure if we need it as we are using `process.env.NODE_ENV` a lot in front-end.
|
||||||
|
'n/prefer-global/buffer': ['error', 'never'],
|
||||||
|
'n/no-callback-literal': 'off',
|
||||||
|
|
||||||
// unicorns
|
// unicorns
|
||||||
// Pass error message when throwing errors
|
// Pass error message when throwing errors
|
||||||
'unicorn/error-message': 'error',
|
'unicorn/error-message': 'error',
|
||||||
@@ -339,13 +366,14 @@ module.exports = {
|
|||||||
'unicorn/throw-new-error': 'error',
|
'unicorn/throw-new-error': 'error',
|
||||||
// Prefer using the node: protocol
|
// Prefer using the node: protocol
|
||||||
'unicorn/prefer-node-protocol': 'error',
|
'unicorn/prefer-node-protocol': 'error',
|
||||||
|
// Prefer using number properties like `Number.isNaN` rather than `isNaN`
|
||||||
|
'unicorn/prefer-number-properties': 'error',
|
||||||
|
|
||||||
'no-use-before-define': ['error', { functions: false, classes: false, variables: true }],
|
'no-use-before-define': ['error', { functions: false, classes: false, variables: true }],
|
||||||
'eslint-comments/disable-enable-pair': 'off',
|
'eslint-comments/disable-enable-pair': 'off',
|
||||||
'import/no-named-as-default-member': 'off',
|
'import/no-named-as-default-member': 'off',
|
||||||
'import/no-named-as-default': 'off',
|
'import/no-named-as-default': 'off',
|
||||||
'import/namespace': 'off',
|
'import/namespace': 'off',
|
||||||
'n/no-callback-literal': 'off',
|
|
||||||
|
|
||||||
'sort-imports': [
|
'sort-imports': [
|
||||||
'error',
|
'error',
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-basic",
|
"name": "@antfu/eslint-config-basic",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -22,19 +22,19 @@
|
|||||||
"eslint-plugin-antfu": "workspace:*",
|
"eslint-plugin-antfu": "workspace:*",
|
||||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||||
"eslint-plugin-html": "^7.1.0",
|
"eslint-plugin-html": "^7.1.0",
|
||||||
"eslint-plugin-import": "^2.27.5",
|
"eslint-plugin-import": "npm:eslint-plugin-i@2.27.5-3",
|
||||||
"eslint-plugin-jsonc": "^2.7.0",
|
"eslint-plugin-jsonc": "^2.8.0",
|
||||||
"eslint-plugin-markdown": "^3.0.0",
|
"eslint-plugin-markdown": "^3.0.0",
|
||||||
"eslint-plugin-n": "^15.7.0",
|
"eslint-plugin-n": "^16.0.0",
|
||||||
"eslint-plugin-no-only-tests": "^3.1.0",
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
||||||
"eslint-plugin-promise": "^6.1.1",
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
"eslint-plugin-unicorn": "^46.0.0",
|
"eslint-plugin-unicorn": "^47.0.0",
|
||||||
"eslint-plugin-unused-imports": "^2.0.0",
|
"eslint-plugin-unused-imports": "^2.0.0",
|
||||||
"eslint-plugin-yml": "^1.5.0",
|
"eslint-plugin-yml": "^1.7.0",
|
||||||
"jsonc-eslint-parser": "^2.2.0",
|
"jsonc-eslint-parser": "^2.3.0",
|
||||||
"yaml-eslint-parser": "^1.2.0"
|
"yaml-eslint-parser": "^1.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.37.0"
|
"eslint": "^8.41.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,20 +9,24 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
},
|
},
|
||||||
|
|
||||||
env: {
|
env: {
|
||||||
es2021: true,
|
es2021: true,
|
||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
'import',
|
'import',
|
||||||
'n',
|
'n',
|
||||||
'promise',
|
'promise',
|
||||||
],
|
],
|
||||||
|
|
||||||
globals: {
|
globals: {
|
||||||
document: 'readonly',
|
document: 'readonly',
|
||||||
navigator: 'readonly',
|
navigator: 'readonly',
|
||||||
window: 'readonly',
|
window: 'readonly',
|
||||||
},
|
},
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
'no-var': 'warn',
|
'no-var': 'warn',
|
||||||
'object-shorthand': ['warn', 'properties'],
|
'object-shorthand': ['warn', 'properties'],
|
||||||
@@ -126,7 +130,7 @@ module.exports = {
|
|||||||
'no-mixed-operators': ['error', {
|
'no-mixed-operators': ['error', {
|
||||||
groups: [
|
groups: [
|
||||||
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
|
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
|
||||||
['&&', '||', '?:'],
|
['&&', '||'],
|
||||||
['in', 'instanceof'],
|
['in', 'instanceof'],
|
||||||
],
|
],
|
||||||
allowSamePrecedence: true,
|
allowSamePrecedence: true,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-react",
|
"name": "@antfu/eslint-config-react",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
"eslint-plugin-react-hooks": "^4.6.0"
|
"eslint-plugin-react-hooks": "^4.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.37.0",
|
"eslint": "^8.41.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"typescript": "^5.0.2"
|
"typescript": "^5.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ module.exports = {
|
|||||||
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', disallowTypeAnnotations: false }],
|
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', disallowTypeAnnotations: false }],
|
||||||
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
||||||
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
||||||
|
'@typescript-eslint/no-require-imports': 'error',
|
||||||
// Override JS
|
// Override JS
|
||||||
'no-useless-constructor': 'off',
|
'no-useless-constructor': 'off',
|
||||||
'indent': 'off',
|
'indent': 'off',
|
||||||
@@ -113,6 +113,8 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
offsetTernaryExpressions: true,
|
offsetTernaryExpressions: true,
|
||||||
}],
|
}],
|
||||||
|
'no-invalid-this': 'off',
|
||||||
|
'@typescript-eslint/no-invalid-this': 'error',
|
||||||
'no-redeclare': 'off',
|
'no-redeclare': 'off',
|
||||||
'@typescript-eslint/no-redeclare': 'error',
|
'@typescript-eslint/no-redeclare': 'error',
|
||||||
'no-use-before-define': 'off',
|
'no-use-before-define': 'off',
|
||||||
@@ -155,6 +157,9 @@ module.exports = {
|
|||||||
|
|
||||||
// antfu
|
// antfu
|
||||||
'antfu/generic-spacing': 'error',
|
'antfu/generic-spacing': 'error',
|
||||||
|
'antfu/no-cjs-exports': 'error',
|
||||||
|
'antfu/no-ts-export-equal': 'error',
|
||||||
|
'antfu/no-const-enum': 'error',
|
||||||
|
|
||||||
// off
|
// off
|
||||||
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
||||||
@@ -169,7 +174,6 @@ module.exports = {
|
|||||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
'@typescript-eslint/ban-types': 'off',
|
'@typescript-eslint/ban-types': 'off',
|
||||||
'@typescript-eslint/no-namespace': 'off',
|
|
||||||
'@typescript-eslint/triple-slash-reference': 'off',
|
'@typescript-eslint/triple-slash-reference': 'off',
|
||||||
// handled by unused-imports/no-unused-imports
|
// handled by unused-imports/no-unused-imports
|
||||||
'@typescript-eslint/no-unused-vars': 'off',
|
'@typescript-eslint/no-unused-vars': 'off',
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-ts",
|
"name": "@antfu/eslint-config-ts",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -18,11 +18,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@antfu/eslint-config-basic": "workspace:*",
|
"@antfu/eslint-config-basic": "workspace:*",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
||||||
"@typescript-eslint/parser": "^5.57.0",
|
"@typescript-eslint/parser": "^5.59.7",
|
||||||
"eslint-plugin-jest": "^27.2.1"
|
"eslint-plugin-jest": "^27.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.37.0"
|
"eslint": "^8.41.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ module.exports = {
|
|||||||
'vue/multi-word-component-names': 'off',
|
'vue/multi-word-component-names': 'off',
|
||||||
'vue/prefer-import-from-vue': 'off',
|
'vue/prefer-import-from-vue': 'off',
|
||||||
'vue/no-v-text-v-html-on-component': 'off',
|
'vue/no-v-text-v-html-on-component': 'off',
|
||||||
|
'vue/no-dupe-keys': 'off',
|
||||||
|
|
||||||
// reactivity transform
|
// reactivity transform
|
||||||
'vue/no-setup-props-destructure': 'off',
|
'vue/no-setup-props-destructure': 'off',
|
||||||
@@ -51,7 +52,7 @@ module.exports = {
|
|||||||
'vue/component-options-name-casing': ['error', 'PascalCase'],
|
'vue/component-options-name-casing': ['error', 'PascalCase'],
|
||||||
'vue/custom-event-name-casing': ['error', 'camelCase'],
|
'vue/custom-event-name-casing': ['error', 'camelCase'],
|
||||||
'vue/define-macros-order': ['error', {
|
'vue/define-macros-order': ['error', {
|
||||||
order: ['defineProps', 'defineEmits'],
|
order: ['defineOptions', 'defineProps', 'defineEmits', 'defineSlots'],
|
||||||
}],
|
}],
|
||||||
'vue/html-comment-content-spacing': ['error', 'always', {
|
'vue/html-comment-content-spacing': ['error', 'always', {
|
||||||
exceptions: ['-'],
|
exceptions: ['-'],
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-vue",
|
"name": "@antfu/eslint-config-vue",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -17,10 +17,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@antfu/eslint-config-basic": "workspace:*",
|
"@antfu/eslint-config-basic": "workspace:*",
|
||||||
"@antfu/eslint-config-ts": "workspace:*",
|
"@antfu/eslint-config-ts": "workspace:*",
|
||||||
"eslint-plugin-vue": "^9.10.0",
|
"eslint-plugin-vue": "^9.14.0",
|
||||||
"local-pkg": "^0.4.3"
|
"local-pkg": "^0.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.37.0"
|
"eslint": "^8.41.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config",
|
"name": "@antfu/eslint-config",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"description": "Anthony's ESLint config",
|
"description": "Anthony's ESLint config",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -17,21 +17,21 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@antfu/eslint-config-vue": "workspace:*",
|
"@antfu/eslint-config-vue": "workspace:*",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
||||||
"@typescript-eslint/parser": "^5.57.0",
|
"@typescript-eslint/parser": "^5.59.7",
|
||||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||||
"eslint-plugin-html": "^7.1.0",
|
"eslint-plugin-html": "^7.1.0",
|
||||||
"eslint-plugin-import": "^2.27.5",
|
"eslint-plugin-import": "npm:eslint-plugin-i@2.27.5-3",
|
||||||
"eslint-plugin-jsonc": "^2.7.0",
|
"eslint-plugin-jsonc": "^2.8.0",
|
||||||
"eslint-plugin-n": "^15.7.0",
|
"eslint-plugin-n": "^16.0.0",
|
||||||
"eslint-plugin-promise": "^6.1.1",
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
"eslint-plugin-unicorn": "^46.0.0",
|
"eslint-plugin-unicorn": "^47.0.0",
|
||||||
"eslint-plugin-vue": "^9.10.0",
|
"eslint-plugin-vue": "^9.14.0",
|
||||||
"eslint-plugin-yml": "^1.5.0",
|
"eslint-plugin-yml": "^1.7.0",
|
||||||
"jsonc-eslint-parser": "^2.2.0",
|
"jsonc-eslint-parser": "^2.3.0",
|
||||||
"yaml-eslint-parser": "^1.2.0"
|
"yaml-eslint-parser": "^1.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.37.0"
|
"eslint": "^8.41.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "eslint-plugin-antfu",
|
"name": "eslint-plugin-antfu",
|
||||||
"version": "0.38.1",
|
"version": "0.39.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/antfu/eslint-config",
|
"homepage": "https://github.com/antfu/eslint-config",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
@@ -16,11 +16,11 @@
|
|||||||
"prepublishOnly": "nr build"
|
"prepublishOnly": "nr build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@typescript-eslint/utils": "^5.57.0"
|
"@typescript-eslint/utils": "^5.59.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.15.11",
|
"@types/node": "^20.2.3",
|
||||||
"unbuild": "^1.1.2",
|
"unbuild": "^1.2.1",
|
||||||
"vitest": "^0.29.8"
|
"vitest": "^0.31.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,9 @@ import ifNewline from './rules/if-newline'
|
|||||||
import importDedupe from './rules/import-dedupe'
|
import importDedupe from './rules/import-dedupe'
|
||||||
import preferInlineTypeImport from './rules/prefer-inline-type-import'
|
import preferInlineTypeImport from './rules/prefer-inline-type-import'
|
||||||
import topLevelFunction from './rules/top-level-function'
|
import topLevelFunction from './rules/top-level-function'
|
||||||
|
import noTsExportEqual from './rules/no-ts-export-equal'
|
||||||
|
import noCjsExports from './rules/no-cjs-exports'
|
||||||
|
import noConstEnum from './rules/no-const-enum'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
rules: {
|
rules: {
|
||||||
@@ -11,5 +14,8 @@ export default {
|
|||||||
'prefer-inline-type-import': preferInlineTypeImport,
|
'prefer-inline-type-import': preferInlineTypeImport,
|
||||||
'generic-spacing': genericSpacing,
|
'generic-spacing': genericSpacing,
|
||||||
'top-level-function': topLevelFunction,
|
'top-level-function': topLevelFunction,
|
||||||
|
'no-cjs-exports': noCjsExports,
|
||||||
|
'no-ts-export-equal': noTsExportEqual,
|
||||||
|
'no-const-enum': noConstEnum,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
|
||||||
|
import { it } from 'vitest'
|
||||||
|
import rule, { RULE_NAME } from './no-cjs-exports'
|
||||||
|
|
||||||
|
const valids = [
|
||||||
|
{ code: 'export = {}', filename: 'test.ts' },
|
||||||
|
{ code: 'exports.a = {}', filename: 'test.js' },
|
||||||
|
{ code: 'module.exports.a = {}', filename: 'test.js' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const invalids = [
|
||||||
|
{ code: 'exports.a = {}', filename: 'test.ts' },
|
||||||
|
{ code: 'module.exports.a = {}', filename: 'test.ts' },
|
||||||
|
]
|
||||||
|
|
||||||
|
it('runs', () => {
|
||||||
|
const ruleTester: RuleTester = new RuleTester({
|
||||||
|
parser: require.resolve('@typescript-eslint/parser'),
|
||||||
|
})
|
||||||
|
|
||||||
|
ruleTester.run(RULE_NAME, rule, {
|
||||||
|
valid: valids,
|
||||||
|
invalid: invalids.map(i => ({
|
||||||
|
...i,
|
||||||
|
errors: [{ messageId: 'noCjsExports' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
41
packages/eslint-plugin-antfu/src/rules/no-cjs-exports.ts
Normal file
41
packages/eslint-plugin-antfu/src/rules/no-cjs-exports.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { createEslintRule } from '../utils'
|
||||||
|
|
||||||
|
export const RULE_NAME = 'no-cjs-exports'
|
||||||
|
export type MessageIds = 'noCjsExports'
|
||||||
|
export type Options = []
|
||||||
|
|
||||||
|
export default createEslintRule<Options, MessageIds>({
|
||||||
|
name: RULE_NAME,
|
||||||
|
meta: {
|
||||||
|
type: 'problem',
|
||||||
|
docs: {
|
||||||
|
description: 'Do not use CJS exports',
|
||||||
|
recommended: false,
|
||||||
|
},
|
||||||
|
schema: [],
|
||||||
|
messages: {
|
||||||
|
noCjsExports: 'Use ESM export instead',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultOptions: [],
|
||||||
|
create: (context) => {
|
||||||
|
const extension = context.getFilename().split('.').pop()
|
||||||
|
if (!['ts', 'tsx', 'mts', 'cts'].includes(extension))
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'MemberExpression[object.name="exports"]': function (node) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noCjsExports',
|
||||||
|
})
|
||||||
|
},
|
||||||
|
'MemberExpression[object.name="module"][property.name="exports"]': function (node) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noCjsExports',
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
25
packages/eslint-plugin-antfu/src/rules/no-const-enum.test.ts
Normal file
25
packages/eslint-plugin-antfu/src/rules/no-const-enum.test.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
|
||||||
|
import { it } from 'vitest'
|
||||||
|
import rule, { RULE_NAME } from './no-const-enum'
|
||||||
|
|
||||||
|
const valids = [
|
||||||
|
'enum E {}',
|
||||||
|
]
|
||||||
|
|
||||||
|
const invalids = [
|
||||||
|
'const enum E {}',
|
||||||
|
]
|
||||||
|
|
||||||
|
it('runs', () => {
|
||||||
|
const ruleTester: RuleTester = new RuleTester({
|
||||||
|
parser: require.resolve('@typescript-eslint/parser'),
|
||||||
|
})
|
||||||
|
|
||||||
|
ruleTester.run(RULE_NAME, rule, {
|
||||||
|
valid: valids,
|
||||||
|
invalid: invalids.map(i => ({
|
||||||
|
code: i,
|
||||||
|
errors: [{ messageId: 'noConstEnum' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
33
packages/eslint-plugin-antfu/src/rules/no-const-enum.ts
Normal file
33
packages/eslint-plugin-antfu/src/rules/no-const-enum.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { createEslintRule } from '../utils'
|
||||||
|
|
||||||
|
export const RULE_NAME = 'no-const-enum'
|
||||||
|
export type MessageIds = 'noConstEnum'
|
||||||
|
export type Options = []
|
||||||
|
|
||||||
|
export default createEslintRule<Options, MessageIds>({
|
||||||
|
name: RULE_NAME,
|
||||||
|
meta: {
|
||||||
|
type: 'problem',
|
||||||
|
docs: {
|
||||||
|
description: 'Disallow using `const enum` expression',
|
||||||
|
recommended: 'error',
|
||||||
|
},
|
||||||
|
schema: [],
|
||||||
|
messages: {
|
||||||
|
noConstEnum: 'Do not use `const enum` expression',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultOptions: [],
|
||||||
|
create: (context) => {
|
||||||
|
return {
|
||||||
|
TSEnumDeclaration: (node) => {
|
||||||
|
if (node.const) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noConstEnum',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
@@ -0,0 +1,26 @@
|
|||||||
|
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
|
||||||
|
import { it } from 'vitest'
|
||||||
|
import rule, { RULE_NAME } from './no-ts-export-equal'
|
||||||
|
|
||||||
|
const valids = [
|
||||||
|
{ code: 'export default {}', filename: 'test.ts' },
|
||||||
|
{ code: 'export = {}', filename: 'test.js' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const invalids = [
|
||||||
|
{ code: 'export = {}', filename: 'test.ts' },
|
||||||
|
]
|
||||||
|
|
||||||
|
it('runs', () => {
|
||||||
|
const ruleTester: RuleTester = new RuleTester({
|
||||||
|
parser: require.resolve('@typescript-eslint/parser'),
|
||||||
|
})
|
||||||
|
|
||||||
|
ruleTester.run(RULE_NAME, rule, {
|
||||||
|
valid: valids,
|
||||||
|
invalid: invalids.map(i => ({
|
||||||
|
...i,
|
||||||
|
errors: [{ messageId: 'noTsExportEqual' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
35
packages/eslint-plugin-antfu/src/rules/no-ts-export-equal.ts
Normal file
35
packages/eslint-plugin-antfu/src/rules/no-ts-export-equal.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { createEslintRule } from '../utils'
|
||||||
|
|
||||||
|
export const RULE_NAME = 'no-ts-export-equal'
|
||||||
|
export type MessageIds = 'noTsExportEqual'
|
||||||
|
export type Options = []
|
||||||
|
|
||||||
|
export default createEslintRule<Options, MessageIds>({
|
||||||
|
name: RULE_NAME,
|
||||||
|
meta: {
|
||||||
|
type: 'problem',
|
||||||
|
docs: {
|
||||||
|
description: 'Do not use `exports =`',
|
||||||
|
recommended: false,
|
||||||
|
},
|
||||||
|
schema: [],
|
||||||
|
messages: {
|
||||||
|
noTsExportEqual: 'Use ESM `export default` instead',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultOptions: [],
|
||||||
|
create: (context) => {
|
||||||
|
const extension = context.getFilename().split('.').pop()
|
||||||
|
if (!['ts', 'tsx', 'mts', 'cts'].includes(extension))
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
TSExportAssignment(node) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noTsExportEqual',
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
@@ -17,28 +17,37 @@ const valids = [
|
|||||||
// allow export default
|
// allow export default
|
||||||
'export default () => {}',
|
'export default () => {}',
|
||||||
'export default defineConfig(() => {})',
|
'export default defineConfig(() => {})',
|
||||||
|
// allow one-line arrow function
|
||||||
|
'const foo = (x, y) => x + y',
|
||||||
|
'const foo = async (x, y) => x + y',
|
||||||
|
'const foo = () => String(123)',
|
||||||
|
'const foo = () => ({})',
|
||||||
]
|
]
|
||||||
|
|
||||||
const invalids = [
|
const invalids = [
|
||||||
|
[
|
||||||
|
'const foo = (x, y) => \nx + y',
|
||||||
|
'function foo (x, y) {\n return x + y\n}',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'const foo = (as: string, bar: number) => { return as + bar }',
|
'const foo = (as: string, bar: number) => { return as + bar }',
|
||||||
'function foo (as: string, bar: number) { return as + bar }',
|
'function foo (as: string, bar: number) { return as + bar }',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'const foo = <K, T extends Boolean>(as: string, bar: number): Omit<T, K> => as + bar',
|
'const foo = <K, T extends Boolean>(as: string, bar: number): Omit<T, K> => \nas + bar',
|
||||||
'function foo <K, T extends Boolean>(as: string, bar: number): Omit<T, K> { return as + bar }',
|
'function foo <K, T extends Boolean>(as: string, bar: number): Omit<T, K> {\n return as + bar\n}',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'export const foo = () => {}',
|
'export const foo = () => {}',
|
||||||
'export function foo () {}',
|
'export function foo () {}',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'export const foo = () => ({})',
|
'export const foo = () => \n({})',
|
||||||
'export function foo () { return {} }',
|
'export function foo () {\n return {}\n}',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'export const foo = async () => ({})',
|
'export const foo = async () => \n({})',
|
||||||
'export async function foo () { return {} }',
|
'export async function foo () {\n return {}\n}',
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@@ -40,6 +40,11 @@ export default createEslintRule<Options, MessageIds>({
|
|||||||
return
|
return
|
||||||
if (declaration.id.typeAnnotation)
|
if (declaration.id.typeAnnotation)
|
||||||
return
|
return
|
||||||
|
if (
|
||||||
|
declaration.init.body.type !== 'BlockStatement'
|
||||||
|
&& declaration.id?.loc.start.line === declaration.init?.body.loc.end.line
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
const arrowFn = declaration.init
|
const arrowFn = declaration.init
|
||||||
const body = declaration.init.body
|
const body = declaration.init.body
|
||||||
@@ -48,8 +53,8 @@ export default createEslintRule<Options, MessageIds>({
|
|||||||
context.report({
|
context.report({
|
||||||
node,
|
node,
|
||||||
loc: {
|
loc: {
|
||||||
start: node.loc.start,
|
start: id.loc.start,
|
||||||
end: node.loc.end,
|
end: body.loc.start,
|
||||||
},
|
},
|
||||||
messageId: 'topLevelFunctionDeclaration',
|
messageId: 'topLevelFunctionDeclaration',
|
||||||
fix(fixer) {
|
fix(fixer) {
|
||||||
@@ -60,7 +65,7 @@ export default createEslintRule<Options, MessageIds>({
|
|||||||
: ''
|
: ''
|
||||||
const textBody = body.type === 'BlockStatement'
|
const textBody = body.type === 'BlockStatement'
|
||||||
? code.slice(body.range[0], body.range[1])
|
? code.slice(body.range[0], body.range[1])
|
||||||
: `{ return ${code.slice(body.range[0], body.range[1])} }`
|
: `{\n return ${code.slice(body.range[0], body.range[1])}\n}`
|
||||||
const textGeneric = arrowFn.typeParameters
|
const textGeneric = arrowFn.typeParameters
|
||||||
? code.slice(arrowFn.typeParameters.range[0], arrowFn.typeParameters.range[1])
|
? code.slice(arrowFn.typeParameters.range[0], arrowFn.typeParameters.range[1])
|
||||||
: ''
|
: ''
|
||||||
|
1383
pnpm-lock.yaml
generated
1383
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user