Skip to content

Flow and linters #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "eslint-config-shakacode",

"plugins": [
"react-native"
"react-native",
"flowtype"
],

"env": {
Expand All @@ -17,6 +18,9 @@
"extensions": [".js", ".android.js", ".ios.js"],
"moduleDirectory": ["..", "node_modules"]
}
},
"flowtype": {
"onlyFilesWithFlowAnnotation": true
}
},

Expand All @@ -31,6 +35,27 @@
"react-native/no-color-literals": 2,
"react/jsx-no-bind": 1,
"react/prefer-stateless-function": 1,
"react/jsx-indent": 1
"react/jsx-indent": 1,

"flowtype/require-parameter-type": 1,
"flowtype/require-return-type": [
0,
"always",
{
"annotateUndefined": "never"
}
],
"flowtype/space-after-type-colon": [
1,
"always"
],
"flowtype/space-before-type-colon": [
1,
"never"
],
"flowtype/type-id-match": [
1,
"^([A-Z][a-z0-9]+)+Type$"
]
}
}
6 changes: 2 additions & 4 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@

# Ignore malformed json
.*/node_modules/y18n/test/.*\.json
.*/node_modules/jsonlint/test/.*\.json

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/

[options]
module.system=haste

esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable

experimental.strict_type_args=true

munge_underscores=true

module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
Expand All @@ -38,4 +36,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-7]\\|1[0-9]\\|[0-9
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy

[version]
^0.27.0
^0.22.1
18 changes: 18 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"preset": "airbnb",
"fileExtensions": [
".js",
".jsx"
],
"excludeFiles": [
"ios/**",
"android/**",
"node_modules/**"
],
"esprima": "babel-jscs",
"validateQuoteMarks": {
"mark": "'",
"escape": true,
"ignoreJSX": true
}
}
1 change: 1 addition & 0 deletions app/App.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import { Provider } from 'react-redux';

Expand Down
3 changes: 2 additions & 1 deletion app/components/AddComment/AddComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { PropTypes } from 'react';
import { Text, View, TextInput } from 'react-native';
import _ from 'lodash/fp';

import ActivityIndicator from 'ReactNativeTutorial/app/components/ActivityIndicator/ActivityIndicator';
import ActivityIndicator from
'ReactNativeTutorial/app/components/ActivityIndicator/ActivityIndicator';
import withFormState from 'ReactNativeTutorial/app/hocs/withFormState';
import withAddCommentHandlers from 'ReactNativeTutorial/app/hocs/withAddCommentHandlers';
import Button from 'ReactNativeTutorial/app/components/Button/Button';
Expand Down
5 changes: 4 additions & 1 deletion app/components/Comments/Comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import _ from 'lodash/fp';

import Comment from 'ReactNativeTutorial/app/components/Comment/Comment';
import Button from 'ReactNativeTutorial/app/components/Button/Button';
import ActivityIndicator from 'ReactNativeTutorial/app/components/ActivityIndicator/ActivityIndicator';
import ActivityIndicator from
'ReactNativeTutorial/app/components/ActivityIndicator/ActivityIndicator';
import withRemoteDataSource from 'ReactNativeTutorial/app/hocs/withRemoteDataSource';
import routes from 'ReactNativeTutorial/app/constants/routes';
import styles from './CommentsStyle';
Expand All @@ -21,13 +22,15 @@ const Comments = (props) => (
props.actions.resetErrorState();
props.remoteDataSourceFetch();
}}

text="Reload"
/>
<Button
onPress={() => {
props.actions.resetErrorState();
props.navigator.push({ path: routes.ADD_COMMENT });
}}

text="Add Comment"
/>
</View>
Expand Down
31 changes: 14 additions & 17 deletions app/hocs/withAddCommentHandlers.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import React, { PropTypes } from 'react';
// @flow
import React from 'react';
import _ from 'lodash/fp';

const withAddCommentHandlers = Component => class extends React.Component {

static propTypes = {
navigator: PropTypes.object.isRequired,
getState: PropTypes.func.isRequired,
actions: PropTypes.shape({
submitCommentRequest: PropTypes.func.isRequired,
resetErrorState: PropTypes.func.isRequired,
}),
error: PropTypes.string,
isSaving: PropTypes.bool,
}

constructor(props) {
const withAddCommentHandlers = (
Component: any
) => class extends React.Component {
constructor(
props: { navigator: Object,
getState: Function,
actions: { submitCommentRequest: Function,
resetErrorState: Function },
error: string,
isSaving: bool }) {
super(props);
_.bindAll(['addComment', 'cancel'], this);
}

componentWillReceiveProps(nextProps) {
componentWillReceiveProps(nextProps: {}) {
if (this.props.isSaving && !nextProps.isSaving && !nextProps.error) {
this.props.actions.resetErrorState();
this.props.navigator.pop();
Expand All @@ -36,7 +33,7 @@ const withAddCommentHandlers = Component => class extends React.Component {
}

render() {
return <Component {...this.props} addComment={this.addComment} cancel={this.cancel} />;
return < Component {...this.props} addComment={this.addComment} cancel={this.cancel} />;
}
};

Expand Down
2 changes: 1 addition & 1 deletion app/hocs/withRemoteDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const withRemoteDataSource = (selector, Component) => class extends React.Compon

static propTypes = {
remoteDataSourceFetch: PropTypes.func.isRequired,
}
};

constructor(props) {
super(props);
Expand Down
1 change: 1 addition & 0 deletions app/libs/api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SAME URL for both post and get
const API_URL = 'http://www.reactrails.com/comments.json';

// const API_URL = 'http://localhost:3000/comments.json';

export default {
Expand Down
2 changes: 1 addition & 1 deletion app/libs/utils/redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const makeActionCreator =
(type: string, ...argNames) => (...args) => _.merge({ type }, _.zipObject(argNames, args));

export const createReducer = ($$initialState: $$Map, handlers: Object) =>
($$state : $$Map = $$initialState, action : { type : string }) =>
($$state : $$Map = $$initialState, action: { type: string }) =>
(
action && handlers.hasOwnProperty(action.type) ?
handlers[action.type]($$state, action) :
Expand Down
5 changes: 3 additions & 2 deletions app/reducers/commentsReducer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
/* eslint new-cap: 0 */

import Immutable, { Map as $$Map } from 'immutable';
Expand Down Expand Up @@ -30,11 +31,11 @@ export const commentsHandlers = {
},

[actionTypes.SUBMIT_COMMENT_SUCCESS]($$state: $$Map, action: { comment: Object }) {
return $$state.withMutations(state => (
return $$state.withMutations((state: $$Map) => (
state
.updateIn(
['$$comments'],
$$comments => $$comments.unshift(Immutable.fromJS(action.comment))
($$comments: Object) => $$comments.unshift(Immutable.fromJS(action.comment))
)
.merge({
error: null,
Expand Down
1 change: 1 addition & 0 deletions app/sagas/submitComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function* submitComment(action) {
if (!comment.hasOwnProperty('author') || !comment.hasOwnProperty('text')) {
throw errors.UNEXPECTED_SERVER_RESPONSE;
}

yield put({ type: actionTypes.SUBMIT_COMMENT_SUCCESS, comment });
} catch (e) {
yield put({ type: actionTypes.SUBMIT_COMMENT_FAILURE, error: e.message || e });
Expand Down
56 changes: 33 additions & 23 deletions ios/ReactNativeTutorial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,27 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = main.jsbundle; sourceTree = "<group>"; };
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = ../node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj; sourceTree = "<group>"; };
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = ../node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj; sourceTree = "<group>"; };
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = ../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj; sourceTree = "<group>"; };
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = "<group>"; };
00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = "../node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj"; sourceTree = "<group>"; };
00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = "../node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj"; sourceTree = "<group>"; };
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = "<group>"; };
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = "<group>"; };
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = "<group>"; };
00E356EE1AD99517003FC87E /* ReactNativeTutorialTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReactNativeTutorialTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* ReactNativeTutorialTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeTutorialTests.m; sourceTree = "<group>"; };
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = ../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj; sourceTree = "<group>"; };
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = ../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj; sourceTree = "<group>"; };
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = "<group>"; };
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* ReactNativeTutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ReactNativeTutorial.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = ReactNativeTutorial/AppDelegate.h; sourceTree = "<group>"; };
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = ReactNativeTutorial/AppDelegate.m; sourceTree = "<group>"; };
13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = ReactNativeTutorial/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ReactNativeTutorial/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ReactNativeTutorial/main.m; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = ../node_modules/react-native/React/React.xcodeproj; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = ../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../node_modules/react-native/Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -352,13 +352,16 @@
83CBB9F71A601CBA00E9B192 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
00E356ED1AD99517003FC87E = {
CreatedOnToolsVersion = 6.2;
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
DevelopmentTeam = YAX6XB3T67;
};
};
};
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeTutorial" */;
Expand Down Expand Up @@ -528,7 +531,6 @@
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh";
showEnvVarsInLog = 1;
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -584,6 +586,7 @@
INFOPLIST_FILE = ReactNativeTutorialTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReactNativeTutorial.app/ReactNativeTutorial";
};
Expand All @@ -597,6 +600,7 @@
INFOPLIST_FILE = ReactNativeTutorialTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReactNativeTutorial.app/ReactNativeTutorial";
};
Expand All @@ -606,19 +610,21 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
DEAD_CODE_STRIPPING = NO;
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**",
);
INFOPLIST_FILE = "ReactNativeTutorial/Info.plist";
INFOPLIST_FILE = ReactNativeTutorial/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = (
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = com.shakacode.rncomments;
PRODUCT_NAME = ReactNativeTutorial;
};
name = Debug;
Expand All @@ -627,18 +633,21 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: ShakaCode, LLC (YAX6XB3T67)";
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**",
);
INFOPLIST_FILE = "ReactNativeTutorial/Info.plist";
INFOPLIST_FILE = ReactNativeTutorial/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = (
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = com.shakacode.rncomments;
PRODUCT_NAME = ReactNativeTutorial;
};
name = Release;
Expand All @@ -663,6 +672,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down
Loading