【发布时间】:2017-04-07 16:29:24
【问题描述】:
我正在尝试配置eslint + babel-eslint + eslint-plugin-react + eslint-plugin-flowtype
我在package.json 中有以下devDependencies:
"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;的检查类型?
【问题讨论】:
标签: javascript eslint flowtype