Compare commits

..

16 Commits

Author SHA1 Message Date
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
13 changed files with 973 additions and 819 deletions

1
.npmrc
View File

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

View File

@@ -1,7 +1,7 @@
{
"type": "module",
"private": true,
"packageManager": "pnpm@8.0.0",
"packageManager": "pnpm@8.1.1",
"scripts": {
"build": "vite-ssg build",
"dev": "vite --port 3333 --open",
@@ -26,7 +26,7 @@
"vue-router": "^4.1.6"
},
"devDependencies": {
"@antfu/eslint-config": "^0.37.0",
"@antfu/eslint-config": "^0.38.3",
"@iconify-json/carbon": "^1.1.16",
"@intlify/vite-plugin-vue-i18n": "^7.0.0",
"@types/markdown-it-link-attributes": "^3.0.1",
@@ -41,10 +41,10 @@
"https-localhost": "^4.7.1",
"markdown-it-link-attributes": "^4.0.1",
"markdown-it-shiki": "^0.8.0",
"pnpm": "^8.0.0",
"pnpm": "^8.1.1",
"shiki": "^0.14.1",
"taze": "^0.9.1",
"typescript": "^5.0.2",
"typescript": "^5.0.3",
"unocss": "^0.50.6",
"unplugin-auto-import": "^0.15.2",
"unplugin-vue-components": "^0.24.1",

View File

@@ -1,8 +1,8 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.38.0",
"version": "0.38.4",
"private": true,
"packageManager": "pnpm@8.0.0",
"packageManager": "pnpm@8.1.1",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
"scripts": {
@@ -12,11 +12,11 @@
"release": "bumpp -r && pnpm -r publish"
},
"devDependencies": {
"@antfu/eslint-config": "*",
"bumpp": "^9.0.0",
"@antfu/eslint-config": "workspace:*",
"bumpp": "^9.1.0",
"eslint": "^8.37.0",
"eslint-plugin-antfu": "workspace:*",
"eslint-plugin-antfu": "link:./packages/eslint-plugin-antfu",
"rimraf": "^4.4.1",
"typescript": "^5.0.2"
"typescript": "^5.0.3"
}
}

View File

@@ -207,6 +207,7 @@ module.exports = {
'import/no-mutable-exports': 'error',
'import/no-unresolved': 'off',
'import/no-absolute-path': 'off',
'import/newline-after-import': ['error', { count: 1 }],
// Common
'semi': ['error', 'never'],
@@ -314,6 +315,11 @@ module.exports = {
'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',
@@ -345,7 +351,6 @@ module.exports = {
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'import/namespace': 'off',
'n/no-callback-literal': 'off',
'sort-imports': [
'error',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.38.0",
"version": "0.38.4",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.38.0",
"version": "0.38.4",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -26,6 +26,6 @@
"devDependencies": {
"eslint": "^8.37.0",
"react": "^18.2.0",
"typescript": "^5.0.2"
"typescript": "^5.0.3"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.38.0",
"version": "0.38.4",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -18,8 +18,8 @@
},
"dependencies": {
"@antfu/eslint-config-basic": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint-plugin-jest": "^27.2.1"
},
"devDependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.38.0",
"version": "0.38.4",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.38.0",
"version": "0.38.4",
"description": "Anthony's ESLint config",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -17,8 +17,8 @@
},
"dependencies": {
"@antfu/eslint-config-vue": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",

View File

@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.38.0",
"version": "0.38.4",
"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.57.0"
"@typescript-eslint/utils": "^5.57.1"
},
"devDependencies": {
"@types/node": "^18.15.11",
"unbuild": "^1.1.2",
"unbuild": "^1.2.0",
"vitest": "^0.29.8"
}
}

View File

@@ -14,6 +14,9 @@ const valids = [
'const foo = (() => {}) as any',
// allow iife
';(() => {})()',
// allow export default
'export default () => {}',
'export default defineConfig(() => {})',
]
const invalids = [
@@ -23,7 +26,7 @@ const invalids = [
],
[
'const foo = <K, T extends Boolean>(as: string, bar: number): Omit<T, K> => as + 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 = () => {}',
@@ -31,7 +34,11 @@ const invalids = [
],
[
'export const foo = () => ({})',
'export function foo () { return {} }',
'export function foo () {\n return {}\n}',
],
[
'export const foo = async () => ({})',
'export async function foo () {\n return {}\n}',
],
]

View File

@@ -48,8 +48,8 @@ export default createEslintRule<Options, MessageIds>({
context.report({
node,
loc: {
start: node.loc.start,
end: node.loc.end,
start: id.loc.start,
end: body.loc.start,
},
messageId: 'topLevelFunctionDeclaration',
fix(fixer) {
@@ -60,19 +60,21 @@ export default createEslintRule<Options, MessageIds>({
: ''
const textBody = body.type === 'BlockStatement'
? 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
? 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 text = `function ${textName} ${textGeneric}(${textArgs})${textTypeReturn} ${textBody}`
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: text,
// output: final,
// })
return fixer.replaceTextRange([node.range[0], node.range[1]], text)
return fixer.replaceTextRange([node.range[0], node.range[1]], final)
},
})
},

1713
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff