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 問題钮糖,只能解決部分)