react native引入flow:(参考:https://medium.com/react-native-training/getting-started-with-react-native-and-flow-d40f55746809)
1、react-native init baseApp
2、查看当前app指定的flow版本
3、yarn add flow-bin@0.67.1 --dev 或者 npm i flow-bin@0.67.1 --save-dev 安装时注意版本号需与当前app中.flowconfig中的版本保持一致
4、在package.json的scripts中配置flow指向的node_modules目录
5、npm run flow
eslint:
1、安装一下依赖
2、在package.json的scripts中配置eslint指向的node_modules目录 其中“src”是你想要eslint进行校验的目录
3、eslintrc.js配置,以下配置供参考
module.exports = {
"env": {
"es6":true,
"node":true
},
"extends":"airbnb",
"parser":"babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread":true,
"jsx":true
},
"sourceType":"module"
},
"plugins": [
"react",
"flowtype",
"react-native",
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
],
"no-eval":"off",
"react/jsx-uses-react":"error",
"react/jsx-uses-vars":"error",
"react/jsx-filename-extension":"off",
"react/require-extension":"off",
"import/extensions":"error",
"import/no-duplicates":"error",
"global-require":"off",
"generator-star-spacing":"off",
"import/no-unresolved": [2, {ignore: ['\.png$','\.jpg$'] }],
"no-duplicate-imports":"off",
"react-native/no-unused-styles":"error",
"flowtype/require-valid-file-annotation": ["error","always"],
"no-throw-literal":"off",
},
"globals": {
"fetch":true,
"FormData":true,
"__DEV__":true,
"$Shape":true,
"eval":true,
}
};
4、npm run eslint -- --fix (其中--fix是自动解决eslint 问题,只能解决部分)