我正在尝试配置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"和下面的.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;的检查类型
发布于 2016-11-23 15:56:11
eslint-plugin-flowtype是而不是流。它是对ESLint的一个扩展,它拥有一组仅与Flow的附加语法相关的lint规则。
例如,有一个规则允许在流对象类型中强制使用逗号或分号(例如,type Foo = {bar: string, baz: number}与type Foo = {bar: string; baz: number})。
但是,要真正实现打字机功能,您需要安装流,并按照说明进行设置。简而言之,它包括确保在项目根上有一个.flowconfig文件,确保在所有文件上都有// @flow头,然后从命令行运行flow status (或者使用核素或其他具有流支持的编辑器)。
发布于 2018-01-02 14:34:53
如果您想让ESLint use来验证您的代码,正确的插件是eslint-plugin-flowtype-errors。
https://www.npmjs.com/package/eslint-plugin-flowtype-errors
正如其他人所写的,eslint-plugin-flowtype只验证带有FlowType语句的代码在语法上是正确的。它实际上不进行流类型验证。
发布于 2016-11-23 15:54:22
eslint-plugin-flowtype 似乎没有一个规则来检查.
linter的目的是执行文体或常规事物(例如总是注释函数返回类型),而不是检查主题类型。
您需要运行Flow本身来检查这些类型是否确实正确。
https://stackoverflow.com/questions/40768266
复制相似问题