Ily*_* Z. 3 javascript eslint flowtype
我正在尝试配置 eslint + babel-eslint + eslint-plugin-react + eslint-plugin-flowtype
我有以下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"
Run Code Online (Sandbox Code Playgroud)
以下内容.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
}
}
}
Run Code Online (Sandbox Code Playgroud)
我写了一个简单的代码示例App.js:
function foo() {
const a: string = 1;
return a;
}
async function bar() {
const b = await foo();
return b;
}
Run Code Online (Sandbox Code Playgroud)
如果我启动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)
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么const a: string = 1;有效.如何启用检查类型const a: string = 1;?
eslint-plugin-flowtype是不流动.它是ESLint的扩展,它具有仅与Flow的附加语法相关的lint规则集合.
例如,有一条规则允许您强制是否在Flow对象类型中使用逗号或分号(例如type Foo = {bar: string, baz: number}vs type Foo = {bar: string; baz: number})
但是,要实际获得类型检查,您需要安装Flow,并按照那里的说明进行设置.简而言之,它涉及确保.flowconfig在项目根目录中有一个文件,确保// @flow在所有文件上都有标题,然后flow status从命令行运行(或使用Nuclide或其他具有Flow支持的编辑器).
| 归档时间: |
|
| 查看次数: |
1979 次 |
| 最近记录: |