我想配置eslint + babel-eslint + eslint-plugin-react + eslint-plugin-flowtype
eslint-插件,流动型不验证
devDependencies
在package.json
我有以下几点:
"babel-eslint": "^7.1.1",
"eslint": "^3.10.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.7.1"
而下面.eslinrc
:
{
"parser": "babel-eslint",
"plugins": [
"flowtype"
],
"extends": [
"airbnb",
"plugin:flowtype/recommended"
],
"rules": {
"max-len": [1, 80, 2, {"ignoreComments": true}],
"prop-types": [0],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/prefer-stateless-function": [
0,
{
"ignorePureComponents": true
}
],
"no-console": 0
},
"settings": {
"flowtype": {
"onlyFilesWithFlowAnnotation": true
}
}
}
我写的简单代码示例App.js
:
function foo() {
const a: string = 1;
return a;
}
async function bar() {
const b = await foo();
return b;
}
如果我启动eslint src/App.js
,则eslint
不显示任何消息。 如果我然后添加到"flowtype/require-return-type": 2
.eslintrc
eslint
显示:
error Missing return type annotation flowtype/require-return-type
error Missing return type annotation flowtype/require-return-type
✖ 2 problems (2 errors, 0 warnings)
但我不明白为什么const a: string = 1;
是有效的。 如何启用检查类型const a: string = 1;
?
谢谢你的答案!你知道是否可以使用'flowtype + eslint'?我的意思是,当我运行'eslint App.js'时,eslint'可能会显示'flowtype'的错误? –
这是可能的,但我没有意识到已经写了一些东西来显示ESLint中的Flow结果。我个人认为这不是一个好主意。更好地按预期使用Flow并按预期使用ESLint,作为单独的工具。 –