将ESLint添加到Meteor+Vue+Typescript项目
我在使用 Meteor、Vue、Typescript 和 prettier 设置 ESLint 时遇到了麻烦。我可以成功解析和格式化 Typescript 文件,但它会引发文件的语法错误.vue。
ESLint 相关依赖
"@babel/plugin-transform-typescript": "^7.12.1",
"@meteorjs/eslint-config-meteor": "^1.0.5",
"@types/meteor": "^1.4.64",
"@types/mocha": "^8.0.3",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-vue-typescript-eslint": "^1.1.7",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-vue": "^7.9.0",
.eslinrc.js
module.exports = {
root: true,
env: {
node: true,
webextensions: true
},
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true // Allows for the parsing of JSX
}
},
settings: {
vue: {
version: 'detect' // Tells eslint-plugin-vue to automatically detect the version of Vue to use
}
},
extends: [
'plugin:vue/recommended',
'eslint:recommended',
'vue-typescript-eslint',
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:prettier/recommended' // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
'no-unused-vars': 'warn'
}
};
.prettierrc.js
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: true,
printWidth: 120,
tabWidth: 4
};
示例页面内容.vue
<template>
<v-row>
<h4>Sample page content</h4>
</v-row>
</template>
<script lang="ts">
import Vue from "vue";
export default Vue.extend( {
components: {},
props: {
giftList: {
type: Object
}
},
});
</script>
<style scoped>
</style>
我ESLint: Parsing error: '}' expected.在该components部分发生了。
我怎样才能让它.vue正确解析/格式化我的文件?
更新 - 设置信息
这是我的问题,显示了最初用于设置我的项目的命令。
https://forums.meteor.com/t/creating-a-meteor-vue-typescript-project-that-uses-class-style-components/55778
meteor create --vue gift-list-app
meteor add typescript
meteor npm install --save-dev @types/meteor
meteor add nathantreid:vue-typescript-babel
meteor npm install --save-dev @babel/plugin-transform-typescript
如果缺少这些开发依赖项,请添加它们。
"devDependencies": {
"@babel/plugin-transform-typescript": "^7.12.1",
"@types/meteor": "^1.4.67",
"@babel/core": "^7.4.4",
"@babel/plugin-syntax-decorators": "^7.2.0",
"@babel/plugin-syntax-jsx": "^7.2.0",
"@babel/preset-typescript": "^7.3.3",
"@babel/plugin-syntax-dynamic-import": "^7.2.0"
}
这是Meteor + Vue + Typescript我创建的一个示例项目。如果 ESLint 可以正确添加到这里,那就完美了。
https://github.com/Michael2109/meteor-vue-typescript-example