Compare commits

...

65 Commits

Author SHA1 Message Date
Anthony Fu
c1355234c0 chore: release v0.39.6 2023-06-28 14:10:34 +02:00
Julian Meinking
6dfc773b05 docs: add eslint.validate to enable linting for supported filetypes with VSCode ESLint (#204)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
2023-06-28 14:10:01 +02:00
曾明健
2bf0c8d727 feat(ts): ban const enum (#201) 2023-06-28 14:05:23 +02:00
arily
504de8392a feat: switch to eslint-plugin-i (#205) 2023-06-28 14:04:55 +02:00
Mert
6cf4794985 docs: update organizeImports config for VS Code (#202) 2023-06-18 12:42:25 +02:00
曾明健
bbed70b969 refactor: use existing rules (#198) 2023-06-06 18:01:05 +02:00
Kirk Lin
f553c519f6 feat(vue): enforce order of define macros (#196) 2023-06-06 11:32:33 +02:00
Anthony Fu
4e77637da4 chore: release v0.39.5 2023-06-04 16:20:46 +02:00
Anthony Fu
abf5c27385 fix: disable @typescript-eslint/consistent-type-assertions 2023-06-04 16:20:42 +02:00
曾明健
7b48da27dc chore(basic): refesh standard.js (#193) 2023-06-02 16:04:48 +02:00
曾明健
0947ddb151 feat(basic): ban deprecated syntax (#194) 2023-06-02 16:04:01 +02:00
L.Rain
0a9c9b0384 chore: simplified off rules (#192) 2023-06-01 16:08:06 +02:00
曾明健
84ae087ea0 chore(basic): add the missing restricted rules about window object (#191) 2023-05-31 14:40:11 +02:00
Anthony Fu
5d908028ca chore: release v0.39.4 2023-05-31 09:53:19 +02:00
Anthony Fu
610d886afd chore: remove window restriction 2023-05-31 09:52:26 +02:00
曾明健
aefa76e48a feat(basic): ban some deprecated global functions (#190) 2023-05-31 09:51:21 +02:00
曾明健
e787e9a647 feat(basic): ban global variable (#189) 2023-05-26 17:39:10 +02:00
曾明健
a3598d36d2 feat(ts): enable @typescript-eslint/consistent-type-assertions (#188) 2023-05-26 17:38:54 +02:00
Anthony Fu
7b399a63db chore: release v0.39.3 2023-05-23 13:39:23 +02:00
Anthony Fu
bb09e1d6b4 fix(vue): disable vue/no-dupe-keys 2023-05-23 13:39:17 +02:00
Anthony Fu
f97f7ef7de chore: release v0.39.2 2023-05-23 12:42:39 +02:00
Anthony Fu
0a19d26da6 chore: update deps 2023-05-23 12:42:31 +02:00
Kaivan Wong
ec494867f9 feat: update eslint-plugin-vue version (#186) 2023-05-23 12:41:23 +02:00
Anthony Fu
656f91ae61 chore: release v0.39.1 2023-05-21 14:19:13 +02:00
Anthony Fu
cdb02c8fa1 fix: turn off cjs-check in markdown 2023-05-21 14:19:11 +02:00
Anthony Fu
3f2f335e42 chore: release v0.39.0 2023-05-19 10:32:15 +02:00
曾明健
3ca0e7ea8b feat(ts): ban cjs exports in ts file (#167) 2023-05-19 10:29:54 +02:00
曾明健
96dd9a1797 feat: validate jsonc file (#184) 2023-05-19 10:29:15 +02:00
Anthony Fu
2db56ec8f0 chore: release v0.38.6 2023-05-05 18:36:15 +02:00
Anthony Fu
6503a153d8 fix: relax markdown lint 2023-05-05 18:35:51 +02:00
cany748
10306427d9 chore: run lint script typo (#180) 2023-05-05 12:27:27 +02:00
Anthony Fu
e6cb79994e fix: exclude vitepress cache 2023-04-19 02:29:07 +02:00
Anthony Fu
a602eb1b4f chore: release v0.38.5 2023-04-18 14:01:56 +02:00
Anthony Fu
9114acddf6 chore: update build 2023-04-18 13:56:51 +02:00
Anthony Fu
e8cec1e2d5 chore: update deps 2023-04-18 13:56:00 +02:00
曾明健
506d17c3f7 feat(plugin): allow some one-line arrow functions (#172) 2023-04-18 13:54:50 +02:00
曾明健
ff74d69719 feat: enable no-invalid-this (#173) 2023-04-18 13:42:48 +02:00
曾明健
e28861a247 fix(basic): allow require imports in js file (#169) 2023-04-11 09:50:52 +02:00
曾明健
9fde0f404f feat(ts): ban namespace in ts file (#166) 2023-04-10 17:45:46 +02:00
曾明健
78b405f91a feat: ban requrie imports in ts file (#165) 2023-04-10 17:39:06 +02:00
曾明健
ebb96c422e feat(basic): consider comments for newline-after-import (#164) 2023-04-10 13:57:57 +02:00
Anthony Fu
5240f68454 chore: release v0.38.4 2023-04-04 08:56:34 +02:00
Anthony Fu
79c8de557e chore: update deps 2023-04-04 08:56:29 +02:00
曾明健
3f13db706b refactor: remove eslint-plugin-node (#162) 2023-04-04 08:55:00 +02:00
Anthony Fu
7a5daf6f38 chore: update lock 2023-04-03 17:19:24 +02:00
Anthony Fu
79b63bc0c9 chore: enable hoist 2023-04-03 14:43:41 +02:00
Anthony Fu
60002c33fd chore: release v0.38.3 2023-04-03 14:42:06 +02:00
曾明健
502f6b0c37 feat(basic): prefer non global object of node (#159)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
2023-04-03 14:41:41 +02:00
曾明健
d1cd722857 feat(basic): new line after import (#161) 2023-04-03 14:30:54 +02:00
Anthony Fu
d2150eec3b fix(top-level-function): narrow warning range 2023-03-30 11:02:49 +02:00
Anthony Fu
d3c3e1b84d chore: update lock 2023-03-30 10:57:04 +02:00
Anthony Fu
3963633712 chore: release v0.38.2 2023-03-30 10:53:40 +02:00
Anthony Fu
e9193343e8 chore: format 2023-03-30 10:53:36 +02:00
Anthony Fu
e8d73f737e chore: release v0.38.1 2023-03-30 10:51:35 +02:00
Anthony Fu
3a74c8e351 fix(top-level-function): support async function 2023-03-30 10:51:29 +02:00
Anthony Fu
3fa861730d test: add more test case 2023-03-30 01:08:42 +02:00
Anthony Fu
ebbc1a7f78 chore: rebuild lock file 2023-03-29 15:52:45 +02:00
Anthony Fu
417b60c18b chore: release v0.38.0 2023-03-29 15:47:19 +02:00
Anthony Fu
9768ccd35e chore: update deps 2023-03-29 15:47:03 +02:00
Anthony Fu
87d26fb63a feat: enforce to use function declaration on top-level 2023-03-29 15:46:16 +02:00
Anthony Fu
e17d2f8f52 docs: update 2023-03-24 10:08:38 +01:00
Anthony Fu
4ef978a092 refactor: rename folders 2023-03-24 10:01:44 +01:00
Anthony Fu
ab850b0ae4 chore: release v0.37.0 2023-03-18 22:01:51 +01:00
Anthony Fu
7632765715 feat: upgrade deps, support typescript 5.0 2023-03-18 22:01:39 +01:00
Ivan Demchuk
d3c1119dbe feat: enable vue/no-unused-refs (#158) 2023-03-16 11:34:58 +01:00
28 changed files with 2332 additions and 1590 deletions

1
.npmrc
View File

@@ -1 +1,2 @@
strict-peer-dependencies=false
shamefully-hoist=true

View File

@@ -3,7 +3,7 @@
[![npm](https://img.shields.io/npm/v/@antfu/eslint-config?color=a1b858&label=)](https://npmjs.com/package/@antfu/eslint-config)
- Single quotes, no semi
- Auto fix for formatting (aimed to be used standalone without Prettier)
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
- Designed to work with TypeScript, Vue out-of-box
- Lint also for json, yaml, markdown
- Sorted imports, dangling commas
@@ -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,
"editor.formatOnSave": false,
"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
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
// .eslintrc.js
@@ -68,9 +88,53 @@ module.exports = {
}
```
## Extended Reading
### Lint Staged
Learn more about the context - [Why I don't use Prettier](https://antfu.me/posts/why-not-prettier).
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
```json
{
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
```
and then
```bash
npm i -D lint-staged simple-git-hooks
```
## FAQ
### Prettier?
[Why I don't use Prettier](https://antfu.me/posts/why-not-prettier)
### How to lint CSS?
This config does NOT lint CSS. I personally use [UnoCSS](https://github.com/unocss/unocss) so I don't write CSS. If you still prefer CSS, you can use [stylelint](https://stylelint.io/) for CSS linting.
### I prefer XXX...
Sure, you can override the rules in your `.eslintrc` file.
<!-- eslint-skip -->
```jsonc
{
"extends": "@antfu",
"rules": {
// your rules...
}
}
```
Or you can always fork this repo and make your own.
## Check Also

View File

@@ -1,7 +1,7 @@
{
"type": "module",
"private": true,
"packageManager": "pnpm@7.8.0",
"packageManager": "pnpm@8.5.1",
"scripts": {
"build": "vite-ssg build",
"dev": "vite --port 3333 --open",
@@ -15,48 +15,48 @@
"up": "taze major -I"
},
"dependencies": {
"@unocss/reset": "^0.50.1",
"@vueuse/core": "^9.13.0",
"@vueuse/head": "^1.1.0",
"@unocss/reset": "^0.52.1",
"@vueuse/core": "^10.1.2",
"@vueuse/head": "^1.1.26",
"nprogress": "^0.2.0",
"pinia": "^2.0.32",
"vue": "^3.2.47",
"vue-demi": "^0.13.11",
"pinia": "^2.1.3",
"vue": "^3.3.4",
"vue-demi": "^0.14.5",
"vue-i18n": "^9.2.2",
"vue-router": "^4.1.6"
"vue-router": "^4.2.1"
},
"devDependencies": {
"@antfu/eslint-config": "^0.35.2",
"@antfu/eslint-config": "^0.39.1",
"@iconify-json/carbon": "^1.1.16",
"@intlify/vite-plugin-vue-i18n": "^7.0.0",
"@types/markdown-it-link-attributes": "^3.0.1",
"@types/nprogress": "^0.2.0",
"@vitejs/plugin-vue": "^4.0.0",
"@vue/test-utils": "^2.3.0",
"@vitejs/plugin-vue": "^4.2.3",
"@vue/test-utils": "^2.3.2",
"critters": "^0.0.16",
"cross-env": "^7.0.3",
"cypress": "^12.6.0",
"eslint": "^8.34.0",
"eslint-plugin-cypress": "^2.12.1",
"cypress": "^12.12.0",
"eslint": "^8.41.0",
"eslint-plugin-cypress": "^2.13.3",
"https-localhost": "^4.7.1",
"markdown-it-link-attributes": "^4.0.1",
"markdown-it-shiki": "^0.8.0",
"pnpm": "^7.27.1",
"shiki": "^0.14.1",
"taze": "^0.8.5",
"typescript": "^4.9.5",
"unocss": "^0.50.1",
"unplugin-auto-import": "^0.15.0",
"unplugin-vue-components": "^0.24.0",
"vite": "^4.1.4",
"vite-plugin-inspect": "^0.7.15",
"vite-plugin-pages": "^0.28.0",
"vite-plugin-pwa": "^0.14.4",
"markdown-it-shiki": "^0.9.0",
"pnpm": "^8.5.1",
"shiki": "^0.14.2",
"taze": "^0.10.1",
"typescript": "^5.0.4",
"unocss": "^0.52.1",
"unplugin-auto-import": "^0.16.2",
"unplugin-vue-components": "^0.24.1",
"vite": "^4.3.8",
"vite-plugin-inspect": "^0.7.26",
"vite-plugin-pages": "^0.30.1",
"vite-plugin-pwa": "^0.15.0",
"vite-plugin-vue-layouts": "^0.8.0",
"vite-plugin-vue-markdown": "^0.22.4",
"vite-ssg": "^0.22.1",
"vite-ssg-sitemap": "^0.4.3",
"vitest": "^0.28.5",
"vue-tsc": "^1.1.7"
"vite-plugin-vue-markdown": "^0.23.5",
"vite-ssg": "^0.22.2",
"vite-ssg-sitemap": "^0.5.1",
"vitest": "^0.31.1",
"vue-tsc": "^1.6.5"
}
}

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
const { t, availableLocales, locale } = useI18n()
const toggleLocales = () => {
function toggleLocales() {
// change to some real logic
const locales = availableLocales
locale.value = locales[(locales.indexOf(locale.value) + 1) % locales.length]

View File

@@ -3,7 +3,7 @@ const user = useUserStore()
const name = $ref(user.savedName)
const router = useRouter()
const go = () => {
function go() {
if (name)
router.push(`/hi/${encodeURIComponent(name)}`)
}

View File

@@ -1,22 +1,23 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.36.0",
"version": "0.39.6",
"private": true,
"packageManager": "pnpm@7.27.1",
"packageManager": "pnpm@8.5.1",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
"scripts": {
"lint": "eslint .",
"lint": "pnpm -r run stub && eslint .",
"test": "pnpm -r run test",
"build": "pnpm -r run build",
"prepare": "pnpm -r run stub",
"release": "bumpp -r && pnpm -r publish"
},
"devDependencies": {
"@antfu/eslint-config": "*",
"bumpp": "^9.0.0",
"eslint": "^8.34.0",
"eslint-plugin-antfu": "workspace:*",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
"@antfu/eslint-config": "workspace:*",
"bumpp": "^9.1.0",
"eslint": "^8.41.0",
"eslint-plugin-antfu": "link:./packages/eslint-plugin-antfu",
"rimraf": "^5.0.1",
"typescript": "^5.0.4"
}
}

View File

@@ -42,6 +42,8 @@ module.exports = {
'!.github',
'!.vitepress',
'!.vscode',
// force exclude
'.vitepress/cache',
],
plugins: [
'html',
@@ -57,7 +59,7 @@ module.exports = {
},
overrides: [
{
files: ['*.json', '*.json5'],
files: ['*.json', '*.json5', '*.jsonc'],
parser: 'jsonc-eslint-parser',
rules: {
'jsonc/array-bracket-spacing': ['error', 'never'],
@@ -154,9 +156,10 @@ module.exports = {
},
},
{
files: ['*.js', '*.cjs'],
files: ['*.js', '*.cjs', '*.jsx'],
rules: {
'@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/comma-dangle': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-require-imports': 'off',
'import/no-unresolved': 'off',
'unused-imports/no-unused-imports': 'off',
'unused-imports/no-unused-vars': 'off',
@@ -197,6 +202,8 @@ module.exports = {
'no-undef': 'off',
'no-unused-expressions': '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-unresolved': 'off',
'import/no-absolute-path': 'off',
'import/newline-after-import': ['error', { count: 1, considerComments: true }],
// Common
'semi': ['error', 'never'],
@@ -232,7 +240,7 @@ module.exports = {
'no-debugger': 'error',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-cond-assign': ['error', 'always'],
'func-call-spacing': ['off', 'never'],
'func-call-spacing': 'off',
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
'indent': ['error', 2, { SwitchCase: 1, VariableDeclarator: 1, outerIIFEBody: 1 }],
'no-restricted-syntax': [
@@ -251,6 +259,19 @@ module.exports = {
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
'no-var': 'error',
@@ -299,7 +320,7 @@ module.exports = {
'array-callback-return': 'error',
'block-scoped-var': 'error',
'consistent-return': 'off',
'complexity': ['off', 11],
'complexity': 'off',
'eqeqeq': ['error', 'smart'],
'no-alert': 'warn',
'no-case-declarations': 'error',
@@ -308,12 +329,18 @@ module.exports = {
'no-with': 'error',
'no-void': 'error',
'no-useless-escape': 'off',
'no-invalid-this': 'error',
'vars-on-top': 'error',
'require-await': 'off',
'no-return-assign': 'off',
'operator-linebreak': ['error', 'before'],
'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
// Pass error message when throwing errors
'unicorn/error-message': 'error',
@@ -339,13 +366,14 @@ module.exports = {
'unicorn/throw-new-error': 'error',
// Prefer using the node: protocol
'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 }],
'eslint-comments/disable-enable-pair': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'import/namespace': 'off',
'n/no-callback-literal': 'off',
'sort-imports': [
'error',
@@ -365,6 +393,7 @@ module.exports = {
// antfu
'antfu/if-newline': 'error',
'antfu/import-dedupe': 'error',
'antfu/top-level-function': 'error',
// 'antfu/prefer-inline-type-import': 'error',
},
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.36.0",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -22,19 +22,19 @@
"eslint-plugin-antfu": "workspace:*",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsonc": "^2.6.0",
"eslint-plugin-import": "npm:eslint-plugin-i@2.27.5-3",
"eslint-plugin-jsonc": "^2.8.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unicorn": "^45.0.2",
"eslint-plugin-unicorn": "^47.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"eslint-plugin-yml": "^1.5.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^1.1.0"
"eslint-plugin-yml": "^1.7.0",
"jsonc-eslint-parser": "^2.3.0",
"yaml-eslint-parser": "^1.2.2"
},
"devDependencies": {
"eslint": "^8.34.0"
"eslint": "^8.41.0"
}
}

View File

@@ -9,20 +9,24 @@ module.exports = {
},
sourceType: 'module',
},
env: {
es2021: true,
node: true,
},
plugins: [
'import',
'n',
'promise',
],
globals: {
document: 'readonly',
navigator: 'readonly',
window: 'readonly',
},
rules: {
'no-var': 'warn',
'object-shorthand': ['warn', 'properties'],
@@ -126,7 +130,7 @@ module.exports = {
'no-mixed-operators': ['error', {
groups: [
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
['&&', '||', '?:'],
['&&', '||'],
['in', 'instanceof'],
],
allowSamePrecedence: true,

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.36.0",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -24,8 +24,8 @@
"eslint-plugin-react-hooks": "^4.6.0"
},
"devDependencies": {
"eslint": "^8.34.0",
"eslint": "^8.41.0",
"react": "^18.2.0",
"typescript": "^4.9.5"
"typescript": "^5.0.4"
}
}

View File

@@ -71,7 +71,7 @@ module.exports = {
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', disallowTypeAnnotations: false }],
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/no-require-imports': 'error',
// Override JS
'no-useless-constructor': 'off',
'indent': 'off',
@@ -113,6 +113,8 @@ module.exports = {
],
offsetTernaryExpressions: true,
}],
'no-invalid-this': 'off',
'@typescript-eslint/no-invalid-this': 'error',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
'no-use-before-define': 'off',
@@ -155,6 +157,9 @@ module.exports = {
// antfu
'antfu/generic-spacing': 'error',
'antfu/no-cjs-exports': 'error',
'antfu/no-ts-export-equal': 'error',
'antfu/no-const-enum': 'error',
// off
'@typescript-eslint/consistent-indexed-object-style': 'off',
@@ -169,7 +174,6 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
// handled by unused-imports/no-unused-imports
'@typescript-eslint/no-unused-vars': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.36.0",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -18,11 +18,11 @@
},
"dependencies": {
"@antfu/eslint-config-basic": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"eslint-plugin-jest": "^27.2.1"
},
"devDependencies": {
"eslint": "^8.34.0"
"eslint": "^8.41.0"
}
}

View File

@@ -36,6 +36,7 @@ module.exports = {
'vue/multi-word-component-names': 'off',
'vue/prefer-import-from-vue': 'off',
'vue/no-v-text-v-html-on-component': 'off',
'vue/no-dupe-keys': 'off',
// reactivity transform
'vue/no-setup-props-destructure': 'off',
@@ -51,13 +52,14 @@ module.exports = {
'vue/component-options-name-casing': ['error', 'PascalCase'],
'vue/custom-event-name-casing': ['error', 'camelCase'],
'vue/define-macros-order': ['error', {
order: ['defineProps', 'defineEmits'],
order: ['defineOptions', 'defineProps', 'defineEmits', 'defineSlots'],
}],
'vue/html-comment-content-spacing': ['error', 'always', {
exceptions: ['-'],
}],
'vue/no-restricted-v-bind': ['error', '/^v-/'],
'vue/no-useless-v-bind': 'error',
'vue/no-unused-refs': 'error',
'vue/padding-line-between-blocks': ['error', 'always'],
'vue/prefer-separate-static-class': 'error',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.36.0",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -17,10 +17,10 @@
"dependencies": {
"@antfu/eslint-config-basic": "workspace:*",
"@antfu/eslint-config-ts": "workspace:*",
"eslint-plugin-vue": "^9.9.0",
"eslint-plugin-vue": "^9.14.0",
"local-pkg": "^0.4.3"
},
"devDependencies": {
"eslint": "^8.34.0"
"eslint": "^8.41.0"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.36.0",
"version": "0.39.6",
"description": "Anthony's ESLint config",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -17,21 +17,21 @@
},
"dependencies": {
"@antfu/eslint-config-vue": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsonc": "^2.6.0",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-import": "npm:eslint-plugin-i@2.27.5-3",
"eslint-plugin-jsonc": "^2.8.0",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unicorn": "^45.0.2",
"eslint-plugin-vue": "^9.9.0",
"eslint-plugin-yml": "^1.5.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^1.1.0"
"eslint-plugin-unicorn": "^47.0.0",
"eslint-plugin-vue": "^9.14.0",
"eslint-plugin-yml": "^1.7.0",
"jsonc-eslint-parser": "^2.3.0",
"yaml-eslint-parser": "^1.2.2"
},
"devDependencies": {
"eslint": "^8.34.0"
"eslint": "^8.41.0"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.36.0",
"version": "0.39.6",
"license": "MIT",
"homepage": "https://github.com/antfu/eslint-config",
"main": "./dist/index.cjs",
@@ -16,11 +16,11 @@
"prepublishOnly": "nr build"
},
"dependencies": {
"@typescript-eslint/utils": "^5.53.0"
"@typescript-eslint/utils": "^5.59.7"
},
"devDependencies": {
"@types/node": "^18.14.1",
"unbuild": "^1.1.2",
"vitest": "^0.28.5"
"@types/node": "^20.2.3",
"unbuild": "^1.2.1",
"vitest": "^0.31.1"
}
}

View File

@@ -2,6 +2,10 @@ import genericSpacing from './rules/generic-spacing'
import ifNewline from './rules/if-newline'
import importDedupe from './rules/import-dedupe'
import preferInlineTypeImport from './rules/prefer-inline-type-import'
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 {
rules: {
@@ -9,5 +13,9 @@ export default {
'import-dedupe': importDedupe,
'prefer-inline-type-import': preferInlineTypeImport,
'generic-spacing': genericSpacing,
'top-level-function': topLevelFunction,
'no-cjs-exports': noCjsExports,
'no-ts-export-equal': noTsExportEqual,
'no-const-enum': noConstEnum,
},
}

View File

@@ -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' }],
})),
})
})

View 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',
})
},
}
},
})

View 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' }],
})),
})
})

View 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',
})
}
},
}
},
})

View File

@@ -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' }],
})),
})
})

View 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',
})
},
}
},
})

View File

@@ -0,0 +1,67 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './top-level-function'
const valids = [
'function foo() {}',
// allow arrow function inside function
'function foo() { const bar = () => {} }',
// allow arrow function when type is specified
'const Foo: Bar = () => {}',
// allow let/var
'let foo = () => {}',
// allow arrow function in as
'const foo = (() => {}) as any',
// allow iife
';(() => {})()',
// allow export default
'export default () => {}',
'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 foo = (x, y) => \nx + y',
'function foo (x, y) {\n return x + y\n}',
],
[
'const 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> => \nas + bar',
'function foo <K, T extends Boolean>(as: string, bar: number): Omit<T, K> {\n return as + bar\n}',
],
[
'export const foo = () => {}',
'export function foo () {}',
],
[
'export const foo = () => \n({})',
'export function foo () {\n return {}\n}',
],
[
'export const foo = async () => \n({})',
'export async function foo () {\n return {}\n}',
],
]
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[0],
output: i[1],
errors: [{ messageId: 'topLevelFunctionDeclaration' }],
})),
})
})

View File

@@ -0,0 +1,88 @@
import { createEslintRule } from '../utils'
export const RULE_NAME = 'top-level-function'
export type MessageIds = 'topLevelFunctionDeclaration'
export type Options = []
export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Enforce top-level functions to be declared with function keyword',
recommended: 'error',
},
fixable: 'code',
schema: [],
messages: {
topLevelFunctionDeclaration: 'Top-level functions should be declared with function keyword',
},
},
defaultOptions: [],
create: (context) => {
return {
VariableDeclaration(node) {
if (node.parent.type !== 'Program' && node.parent.type !== 'ExportNamedDeclaration')
return
if (node.declarations.length !== 1)
return
if (node.kind !== 'const')
return
if (node.declare)
return
const declaration = node.declarations[0]
if (declaration.init?.type !== 'ArrowFunctionExpression')
return
if (declaration.id?.type !== 'Identifier')
return
if (declaration.id.typeAnnotation)
return
if (
declaration.init.body.type !== 'BlockStatement'
&& declaration.id?.loc.start.line === declaration.init?.body.loc.end.line
)
return
const arrowFn = declaration.init
const body = declaration.init.body
const id = declaration.id
context.report({
node,
loc: {
start: id.loc.start,
end: body.loc.start,
},
messageId: 'topLevelFunctionDeclaration',
fix(fixer) {
const code = context.getSourceCode().text
const textName = code.slice(id.range[0], id.range[1])
const textArgs = arrowFn.params.length
? code.slice(arrowFn.params[0].range[0], arrowFn.params[arrowFn.params.length - 1].range[1])
: ''
const textBody = body.type === 'BlockStatement'
? code.slice(body.range[0], body.range[1])
: `{\n return ${code.slice(body.range[0], body.range[1])}\n}`
const textGeneric = arrowFn.typeParameters
? code.slice(arrowFn.typeParameters.range[0], arrowFn.typeParameters.range[1])
: ''
const textTypeReturn = arrowFn.returnType
? code.slice(arrowFn.returnType.range[0], arrowFn.returnType.range[1])
: ''
const textAsync = arrowFn.async ? 'async ' : ''
const final = `${textAsync}function ${textName} ${textGeneric}(${textArgs})${textTypeReturn} ${textBody}`
// console.log({
// input: code.slice(node.range[0], node.range[1]),
// output: final,
// })
return fixer.replaceTextRange([node.range[0], node.range[1]], final)
},
})
},
}
},
})

3276
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff