我对Vue完全陌生。
我想使用CLI,我希望有4个空格缩进(带有类型记录和vuex)。但是在24小时的挣扎之后,我已经没有任何进展了。如果不可能的话,也让我知道。
我以为tslint是走的路,但却找不到解决办法。所以我试了一下,把这个添加到package.json中
"devDependencies": {
"@vue/cli-plugin-eslint": "^3.0.4",
"@vue/cli-plugin-pwa": "^3.0.4",
"@vue/cli-plugin-typescript": "^3.0.4",
"@vue/cli-service": "^3.0.4",
"@vue/eslint-config-prettier": "^3.0.4",
"@vue/eslint-config-typescript": "^3.0.4",
"eslint": "^5.6.1",
"eslint-plugin-vue": "^5.0.0-beta.3", // <------------------
"typescript": "^3.0.0",
"vue-template-compiler": "^2.5.17"
}那我有埃林茨吗
module.exports = {
root: true,
env: {
node: true
},
extends: ["plugin:vue/essential", "@vue/prettier", "@vue/typescript"],
rules: {
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
"vue/script-indent": ["error", 4, { baseIndent: 1 }],
indent: ["error", 4]
},
parserOptions: {
parser: "typescript-eslint-parser"
}
};当我跑的时候
$ npx eslint --fix *.js
=============
WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.
You may find that it works just fine, or you may not.
SUPPORTED TYPESCRIPT VERSIONS: ~3.0.1
YOUR TYPESCRIPT VERSION: 3.1.1
Please only submit bug reports when using the officially supported version.
=============
/Users/x/code/sync/vue/restos2/postcss.config.js
2:1 error Expected indentation of 4 spaces but found 2 indent
3:1 error Expected indentation of 8 spaces but found 4 indent
4:1 error Expected indentation of 4 spaces but found 2 indent
✖ 3 problems (3 errors, 0 warnings)
3 errors and 0 warnings potentially fixable with the `--fix` option.
but the problem is that no files ever get changed.发布于 2018-10-09 12:18:59
正如tslint doc中所描述的,缩进规则没有修正缩进字符的错误数量,它只修正了字符类型,这意味着它可以将制表符转换为空格,反之亦然,但它没有将4个空格固定为2个空格。
注意:自动修复只会将无效的缩进空格转换为所需的类型,它不会修复无效的空格大小。
https://palantir.github.io/tslint/rules/indent/
所以是的,你得和埃林特一起去。我没有看到完整的eslintrc文件,但我认为主要的问题可能是这一行:indent: ["error", 4]。试着移除它。
这个eslint配置适合我:
{
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"@vue/typescript"
],
"rules": {
"vue/script-indent": ["error",2,{"baseIndent": 1}]
},
"parserOptions": {
"parser": "typescript-eslint-parser"
}
}并与npm run lint一起运行
https://stackoverflow.com/questions/52707751
复制相似问题