diff --git a/packages/vant-eslint-config/index.js b/packages/vant-eslint-config/index.js index 2b0f404be..9cf0701fc 100644 --- a/packages/vant-eslint-config/index.js +++ b/packages/vant-eslint-config/index.js @@ -1,8 +1,8 @@ module.exports = { extends: [ + 'plugin:vue/vue3-recommended', 'airbnb-base', 'plugin:@typescript-eslint/recommended', - 'plugin:vue/vue3-recommended', 'prettier', 'prettier/vue', 'prettier/@typescript-eslint', @@ -67,6 +67,10 @@ module.exports = { }, overrides: [ + { + files: ['*.vue'], + parser: require.resolve('vue-eslint-parser') + }, { files: ['**/*.md/*.js', '**/*.md/*.ts'], rules: { diff --git a/packages/vant-eslint-config/test/.eslintrc b/packages/vant-eslint-config/test/.eslintrc new file mode 100644 index 000000000..8d53de665 --- /dev/null +++ b/packages/vant-eslint-config/test/.eslintrc @@ -0,0 +1,4 @@ +{ + "root": true, + "extends": ["../index"] +} diff --git a/packages/vant-eslint-config/test/index.spec.js b/packages/vant-eslint-config/test/index.spec.js new file mode 100644 index 000000000..ca2082f13 --- /dev/null +++ b/packages/vant-eslint-config/test/index.spec.js @@ -0,0 +1,38 @@ +const { ESLint } = require('eslint'); +const path = require('path'); + +const eslint = new ESLint(); + +async function lintProject(name) { + const projectPath = path.resolve(__dirname, name); + const filesToLint = path.resolve(projectPath, '**'); + const rest = await eslint.lintFiles(filesToLint); + const ruleId = []; + rest.forEach((res) => + res.messages.forEach((msg) => { + if (ruleId.indexOf(msg.ruleId) < 0) { + ruleId.push(msg.ruleId); + } + }) + ); + return ruleId; +} + +test('a vue project should pass lint', async () => { + const rest = await lintProject('vue'); + expect([ + 'no-const-assign', + '@typescript-eslint/no-unused-vars', + 'no-undef', + ]).toEqual(rest); +}); + +test('a vue-tsx project should pass lint', async () => { + const rest = await lintProject('vue-tsx'); + + expect([ + '@typescript-eslint/no-unused-vars', + 'vue/no-ref-as-operand', + '@typescript-eslint/no-empty-interface', + ]).toEqual(rest); +}); diff --git a/packages/vant-eslint-config/test/vue-tsx/app.tsx b/packages/vant-eslint-config/test/vue-tsx/app.tsx new file mode 100644 index 000000000..caae23bed --- /dev/null +++ b/packages/vant-eslint-config/test/vue-tsx/app.tsx @@ -0,0 +1,12 @@ +import { defineComponent } from 'vue' + +export default defineComponent({ + name: 'App', + setup() { + return () => ( + <> +