Compare commits

...

28 Commits

Author SHA1 Message Date
Anthony Fu
6189a9225c chore: release v0.31.1 2022-11-29 17:33:07 +08:00
Anthony Fu
46a39e1506 chore: update deps 2022-11-29 17:33:00 +08:00
lainbo
1c37b247c5 feat: support TS 4.9 (#133) 2022-11-29 17:27:36 +08:00
Anthony Fu
2a1e59f43b chore: release v0.31.0 2022-11-17 01:27:39 +08:00
Anthony Fu
94b5fdddad chore: update deps 2022-11-17 01:27:16 +08:00
曾明健
65aec3f101 feat(basic): add max-statements-per-line (#129) 2022-11-17 01:25:16 +08:00
Anthony Fu
b53ffae83e chore: release v0.30.1 2022-11-12 15:06:28 +08:00
Anthony Fu
20c01380c9 fix: move deps 2022-11-12 15:06:25 +08:00
Anthony Fu
6b3f6e620b chore: release v0.30.0 2022-11-12 15:04:52 +08:00
Anthony Fu
693eba91a8 chore: update deps 2022-11-12 15:04:41 +08:00
Anthony Fu
b820b0fd92 feat: auto JS fallback 2022-11-12 15:03:35 +08:00
Anthony Fu
f8014b745e chore: release v0.29.4 2022-11-07 21:04:08 +08:00
Anthony Fu
95e28e4a4a fix(generic-spacing): improve cases 2022-11-07 21:03:56 +08:00
Anthony Fu
54b234f4ef chore: release v0.29.3 2022-11-02 17:21:31 +08:00
Anthony Fu
ff6a1fad6a fix(generic-spacing): improve cases 2022-11-02 17:21:24 +08:00
Anthony Fu
e13613fd5f chore: release v0.29.2 2022-11-01 04:01:12 +08:00
Anthony Fu
e111029e0a feat(generic-spacing): remove space before generic 2022-11-01 04:00:59 +08:00
Anthony Fu
254f8194df chore: release v0.29.1 2022-11-01 03:38:15 +08:00
Anthony Fu
4119f52750 fix(generic-spacing): avoid overriding extends 2022-11-01 03:38:06 +08:00
Anthony Fu
4b51ef2eba chore: release v0.29.0 2022-11-01 03:34:28 +08:00
Anthony Fu
588494cc01 feat: format for generics spacing 2022-11-01 03:34:15 +08:00
Anthony Fu
3c1207657f chore: release v0.28.0 2022-11-01 02:35:18 +08:00
KylinDC
da59484756 feat(basic): add rules to prevent .only in tests (#127) 2022-11-01 02:28:00 +08:00
Zhou Yunliang
501ff74200 chore: add missing dependency (#125) 2022-10-26 16:42:07 +08:00
zhangenming
adaf70b651 docs: add install extension tip (#123)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
2022-10-22 17:09:14 +08:00
Anthony Fu
3ed0230512 docs: prefer to blog post 2022-10-10 07:33:09 +08:00
Marvin
ac3f63086d docs: suggest to disable format on save (#118) 2022-10-01 02:45:37 +08:00
Anthony Fu
f7a5571259 chore: update readme 2022-09-19 10:30:50 +08:00
18 changed files with 979 additions and 667 deletions

View File

@@ -4,7 +4,7 @@
- Single quotes, no semi
- Auto fix for formatting (aimed to be used standalone without Prettier)
- TypeScript, Vue, React out-of-box
- Designed to work with TypeScript, Vue out-of-box
- Lint also for json, yaml, markdown
- Sorted imports, dangling commas for cleaner commit diff
- Reasonable defaults, best practices, only one-line of config
@@ -42,22 +42,26 @@ For example:
### Config VS Code auto fix
Create `.vscode/settings.json`
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and create `.vscode/settings.json`
```json
{
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
```
## Extended Reading
Learn more about the context - [Why I don't use Prettier](https://antfu.me/posts/why-not-prettier).
## Check Also
- [antfu/dotfiles](https://github.com/antfu/dotfiles) - My dotfiles
- [antfu/vscode-settings](https://github.com/antfu/vscode-settings) - My VS Code settings
- [antfu/eslint-config](https://github.com/antfu/eslint-config) - My ESLint config
- [antfu/ts-starter](https://github.com/antfu/ts-starter) - My starter template for TypeScript library
- [antfu/vitesse](https://github.com/antfu/vitesse) - My starter template for Vue & Vite app

View File

@@ -15,48 +15,48 @@
"up": "taze major -I"
},
"dependencies": {
"@unocss/reset": "^0.45.8",
"@vueuse/core": "^9.1.0",
"@vueuse/head": "^0.7.9",
"@unocss/reset": "^0.47.0",
"@vueuse/core": "^9.6.0",
"@vueuse/head": "^1.0.18",
"nprogress": "^0.2.0",
"pinia": "^2.0.17",
"vue": "^3.2.37",
"vue-demi": "^0.13.6",
"pinia": "^2.0.27",
"vue": "^3.2.45",
"vue-demi": "^0.13.11",
"vue-i18n": "^9.2.2",
"vue-router": "^4.1.3"
"vue-router": "^4.1.6"
},
"devDependencies": {
"@antfu/eslint-config": "^0.25.2",
"@iconify-json/carbon": "^1.1.7",
"@intlify/vite-plugin-vue-i18n": "^6.0.0",
"@antfu/eslint-config": "^0.31.0",
"@iconify-json/carbon": "^1.1.11",
"@intlify/vite-plugin-vue-i18n": "^6.0.3",
"@types/markdown-it-link-attributes": "^3.0.1",
"@types/nprogress": "^0.2.0",
"@vitejs/plugin-vue": "^3.0.1",
"@vue/test-utils": "^2.0.2",
"@vitejs/plugin-vue": "^3.2.0",
"@vue/test-utils": "^2.2.4",
"critters": "^0.0.16",
"cross-env": "^7.0.3",
"cypress": "^10.4.0",
"eslint": "^8.21.0",
"cypress": "^11.2.0",
"eslint": "^8.28.0",
"eslint-plugin-cypress": "^2.12.1",
"https-localhost": "^4.7.1",
"markdown-it-link-attributes": "^4.0.0",
"markdown-it-shiki": "^0.5.1",
"pnpm": "^7.8.0",
"shiki": "^0.10.1",
"taze": "^0.7.6",
"typescript": "^4.7.4",
"unocss": "^0.45.5",
"unplugin-auto-import": "^0.11.0",
"unplugin-vue-components": "^0.22.0",
"vite": "^3.0.4",
"vite-plugin-inspect": "^0.6.0",
"vite-plugin-pages": "^0.25.0",
"vite-plugin-pwa": "^0.12.3",
"markdown-it-link-attributes": "^4.0.1",
"markdown-it-shiki": "^0.6.1",
"pnpm": "^7.17.1",
"shiki": "^0.11.1",
"taze": "^0.8.4",
"typescript": "^4.9.3",
"unocss": "^0.47.0",
"unplugin-auto-import": "^0.12.0",
"unplugin-vue-components": "^0.22.11",
"vite": "^3.2.4",
"vite-plugin-inspect": "^0.7.9",
"vite-plugin-pages": "^0.27.1",
"vite-plugin-pwa": "^0.13.3",
"vite-plugin-vue-layouts": "^0.7.0",
"vite-plugin-vue-markdown": "^0.21.1",
"vite-ssg": "^0.20.2",
"vite-ssg-sitemap": "^0.3.1",
"vitest": "^0.21.0",
"vue-tsc": "^0.39.5"
"vite-plugin-vue-markdown": "^0.22.1",
"vite-ssg": "^0.22.0",
"vite-ssg-sitemap": "^0.4.3",
"vitest": "^0.25.3",
"vue-tsc": "^1.0.9"
}
}

View File

@@ -7,6 +7,8 @@ export const install: UserModule = ({ isClient, router }) => {
if (to.path !== from.path)
NProgress.start()
})
router.afterEach(() => { NProgress.done() })
router.afterEach(() => {
NProgress.done()
})
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.27.0",
"version": "0.31.1",
"private": true,
"packageManager": "pnpm@7.1.0",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -14,8 +14,9 @@
"devDependencies": {
"@antfu/eslint-config": "*",
"bumpp": "^8.2.1",
"eslint": "^8.23.0",
"eslint": "^8.28.0",
"eslint-plugin-antfu": "workspace:*",
"typescript": "^4.8.2"
"rimraf": "^3.0.2",
"typescript": "^4.9.3"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.27.0",
"version": "0.31.1",
"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.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsonc": "^2.4.0",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-unicorn": "^43.0.2",
"eslint-plugin-vue": "^9.4.0",
"eslint-plugin-yml": "^1.1.0",
"eslint-plugin-jsonc": "^2.5.0",
"eslint-plugin-n": "^15.5.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unicorn": "^45.0.1",
"eslint-plugin-vue": "^9.8.0",
"eslint-plugin-yml": "^1.2.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^1.1.0"
},
"devDependencies": {
"eslint": "^8.23.0"
"eslint": "^8.28.0"
}
}

View File

@@ -35,6 +35,7 @@ module.exports = {
'html',
'unicorn',
'antfu',
'no-only-tests',
],
settings: {
'import/resolver': {
@@ -155,6 +156,7 @@ module.exports = {
files: ['*.test.ts', '*.test.js', '*.spec.ts', '*.spec.js'],
rules: {
'no-unused-expressions': 'off',
'no-only-tests/no-only-tests': 'error',
},
},
{
@@ -283,6 +285,7 @@ module.exports = {
'require-await': 'off',
'no-return-assign': 'off',
'operator-linebreak': ['error', 'before'],
'max-statements-per-line': ['error', { max: 1 }],
// unicorns
// Pass error message when throwing errors

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.27.0",
"version": "0.31.1",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -23,16 +23,17 @@
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsonc": "^2.4.0",
"eslint-plugin-jsonc": "^2.5.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-unicorn": "^43.0.2",
"eslint-plugin-yml": "^1.1.0",
"eslint-plugin-n": "^15.5.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unicorn": "^45.0.1",
"eslint-plugin-yml": "^1.2.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^1.1.0"
},
"devDependencies": {
"eslint": "^8.23.0"
"eslint": "^8.28.0"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.27.0",
"version": "0.31.1",
"license": "MIT",
"homepage": "https://github.com/antfu/eslint-config",
"main": "./dist/index.cjs",
@@ -16,10 +16,11 @@
"prepublishOnly": "nr build"
},
"dependencies": {
"@typescript-eslint/utils": "^5.36.1"
"@typescript-eslint/utils": "^5.45.0"
},
"devDependencies": {
"unbuild": "^0.8.10",
"vitest": "^0.22.1"
"@types/node": "^18.11.9",
"unbuild": "^1.0.1",
"vitest": "^0.25.3"
}
}

View File

@@ -1,3 +1,4 @@
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'
@@ -7,5 +8,6 @@ export default {
'if-newline': ifNewline,
'import-dedupe': importDedupe,
'prefer-inline-type-import': preferInlineTypeImport,
'generic-spacing': genericSpacing,
},
}

View File

@@ -0,0 +1,52 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './generic-spacing'
const valids = [
'type Foo<T = true> = T',
'type Foo<T extends true = true> = T',
`
type Foo<
T = true,
K = false
> = T`,
`function foo<
T
>() {}`,
'const foo = <T>(name: T) => name',
`interface Log {
foo<T>(name: T): void
}`,
`interface Log {
<T>(name: T): void
}`,
`interface Foo {
foo?: <T>(name: T) => void
}`,
]
const invalids = [
['type Foo<T=true> = T', 'type Foo<T = true> = T'],
['type Foo<T,K> = T', 'type Foo<T, K> = T'],
['type Foo<T=false,K=1|2> = T', 'type Foo<T = false, K = 1|2> = T', 3],
['function foo <T>() {}', 'function foo<T>() {}'],
[`interface Log {
foo <T>(name: T): void
}`, `interface Log {
foo<T>(name: T): void
}`],
] as const
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].trim(),
errors: Array.from({ length: i[2] || 1 }, () => ({ messageId: 'genericSpacingMismatch' })),
})),
})
})

View File

@@ -0,0 +1,87 @@
import { createEslintRule } from '../utils'
export const RULE_NAME = 'generic-spacing'
export type MessageIds = 'genericSpacingMismatch'
export type Options = []
export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'suggestion',
docs: {
description: 'Spaces around generic type parameters',
recommended: 'error',
},
fixable: 'code',
schema: [],
messages: {
genericSpacingMismatch: 'Generic spaces mismatch',
},
},
defaultOptions: [],
create: (context) => {
const sourceCode = context.getSourceCode()
return {
TSTypeParameterDeclaration: (node) => {
if (!['TSCallSignatureDeclaration', 'ArrowFunctionExpression', 'TSFunctionType'].includes(node.parent.type)) {
const pre = sourceCode.text.slice(0, node.range[0])
const preSpace = pre.match(/(\s+)$/)?.[0]
// strip space before <T>
if (preSpace && preSpace.length) {
context.report({
node,
messageId: 'genericSpacingMismatch',
*fix(fixer) {
yield fixer.replaceTextRange([node.range[0] - preSpace.length, node.range[0]], '')
},
})
}
}
// add space between <T,K>
const params = node.params
for (let i = 1; i < params.length; i++) {
const prev = params[i - 1]
const current = params[i]
const from = prev.range[1]
const to = current.range[0]
const span = sourceCode.text.slice(from, to)
if (span !== ', ' && !span.match(/,\n/)) {
context.report({
*fix(fixer) {
yield fixer.replaceTextRange([from, to], ', ')
},
loc: {
start: prev.loc.end,
end: current.loc.start,
},
messageId: 'genericSpacingMismatch',
node,
})
}
}
},
// add space around = in type Foo<T = true>
TSTypeParameter: (node) => {
if (!node.default)
return
const endNode = node.constraint || node.name
const from = endNode.range[1]
const to = node.default.range[0]
if (sourceCode.text.slice(from, to) !== ' = ') {
context.report({
*fix(fixer) {
yield fixer.replaceTextRange([from, to], ' = ')
},
loc: {
start: endNode.loc.end,
end: node.default.loc.start,
},
messageId: 'genericSpacingMismatch',
node,
})
}
},
}
},
})

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.27.0",
"version": "0.31.1",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -20,12 +20,12 @@
},
"dependencies": {
"@antfu/eslint-config-ts": "workspace:*",
"eslint-plugin-react": "^7.31.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0"
},
"devDependencies": {
"eslint": "^8.23.0",
"eslint": "^8.28.0",
"react": "^18.2.0",
"typescript": "^4.8.2"
"typescript": "^4.9.3"
}
}

View File

@@ -106,6 +106,9 @@ module.exports = {
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
// antfu
'antfu/generic-spacing': 'error',
// The following rule overrides require a parser service, aka. require a `typescript.json` path.
// This needs to be done individually for each project, and it slows down linting significantly.
// 'no-throw-literal': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.27.0",
"version": "0.31.1",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -18,10 +18,10 @@
},
"dependencies": {
"@antfu/eslint-config-basic": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1"
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0"
},
"devDependencies": {
"eslint": "^8.23.0"
"eslint": "^8.28.0"
}
}

View File

@@ -1,3 +1,10 @@
const { isPackageExists } = require('local-pkg')
const TS = isPackageExists('typescript')
if (!TS)
console.warn('[@antfu/eslint-config] TypeScript is not installed, fallback to JS only.')
module.exports = {
overrides: [
{
@@ -9,13 +16,17 @@ module.exports = {
rules: {
'no-unused-vars': 'off',
'no-undef': 'off',
'@typescript-eslint/no-unused-vars': 'off',
...(TS
? { '@typescript-eslint/no-unused-vars': 'off' }
: null),
},
},
],
extends: [
'plugin:vue/vue3-recommended',
'@antfu/eslint-config-ts',
TS
? '@antfu/eslint-config-ts'
: '@antfu/eslint-config-basic',
],
rules: {
'vue/max-attributes-per-line': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.27.0",
"version": "0.31.1",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -15,10 +15,12 @@
"eslint": ">=7.4.0"
},
"dependencies": {
"@antfu/eslint-config-basic": "workspace:*",
"@antfu/eslint-config-ts": "workspace:*",
"eslint-plugin-vue": "^9.4.0"
"eslint-plugin-vue": "^9.8.0",
"local-pkg": "^0.4.2"
},
"devDependencies": {
"eslint": "^8.23.0"
"eslint": "^8.28.0"
}
}

1326
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,9 @@
{
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"target": "es2020",
"module": "es2020",
"moduleResolution": "node"
},
"include": [
"./packages/**/*.ts"