From b820b0fd92fe18056bfca76066715028a4869dc9 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 12 Nov 2022 15:03:35 +0800 Subject: [PATCH] feat: auto JS fallback --- packages/vue/index.js | 15 +++++++++++++-- packages/vue/package.json | 4 +++- pnpm-lock.yaml | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/vue/index.js b/packages/vue/index.js index cba50c0e66..7a06812d96 100644 --- a/packages/vue/index.js +++ b/packages/vue/index.js @@ -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', diff --git a/packages/vue/package.json b/packages/vue/package.json index 8901e9969e..912002954f 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -16,9 +16,11 @@ }, "dependencies": { "@antfu/eslint-config-ts": "workspace:*", + "@antfu/eslint-config-basic": "workspace:*", "eslint-plugin-vue": "^9.4.0" }, "devDependencies": { - "eslint": "^8.23.0" + "eslint": "^8.23.0", + "local-pkg": "^0.4.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9abc70056a..b9fdfde9f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -131,14 +131,18 @@ importers: packages/vue: specifiers: + '@antfu/eslint-config-basic': workspace:* '@antfu/eslint-config-ts': workspace:* eslint: ^8.23.0 eslint-plugin-vue: ^9.4.0 + local-pkg: ^0.4.2 dependencies: + '@antfu/eslint-config-basic': link:../basic '@antfu/eslint-config-ts': link:../typescript eslint-plugin-vue: 9.4.0_eslint@8.23.0 devDependencies: eslint: 8.23.0 + local-pkg: 0.4.2 packages: