Skip to content

Commit

Permalink
Merge pull request #1 from mfrachet/feature/prettier
Browse files Browse the repository at this point in the history
feature(prettier): Adding prettier
  • Loading branch information
Marvin Frachet committed Oct 26, 2017
2 parents adc10e3 + afa1344 commit bc75fe2
Show file tree
Hide file tree
Showing 12 changed files with 1,418 additions and 876 deletions.
22 changes: 10 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module.exports = {
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import"
],
"rules": {
"react/jsx-filename-extension": "off",
"jsx-a11y/img-has-alt": "off"
extends: 'airbnb',
plugins: ['react', 'jsx-a11y', 'import'],
rules: {
'react/jsx-filename-extension': 'off',
'jsx-a11y/img-has-alt': 'off',
'jsx-a11y/href-no-hash': 'off',
'import/no-extraneous-dependencies': 'off',
},
env: {
jest: true,
},
"env": {
"jest": true
}
};
11 changes: 4 additions & 7 deletions Example/src/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Title from './Title';

export default class CustomFlatList extends React.Component {
static renderRow({ item }) {
return <RowItem item={{ title: item }} />
return <RowItem item={{ title: item }} />;
}

/**
Expand All @@ -14,12 +14,9 @@ export default class CustomFlatList extends React.Component {
render() {
return (
<View>
<Title value="Variant FlatList" color="#5C6BC0"/>
<FlatList
data={this.props.data}
renderItem={CustomFlatList.renderRow}
/>
<Title value="Variant FlatList" color="#5C6BC0" />
<FlatList data={this.props.data} renderItem={CustomFlatList.renderRow} />
</View>
);
}
}
}
5 changes: 3 additions & 2 deletions Example/src/List.ab-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import AbHoc from 'react-native-ab-hoc';
import FlatList from './FlatList';
import ListView from './ListView';

export default AbHoc('ListView',
export default AbHoc(
'ListView',
{ variant: 'ListView', component: ListView },
{ variant: 'FlatList', component: FlatList }
{ variant: 'FlatList', component: FlatList },
);
27 changes: 12 additions & 15 deletions Example/src/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@ import RowItem from './RowItem';
import Title from './Title';

export default class CustomListView extends React.Component {
constructor(props) {
super(props);
constructor(props) {
super(props);
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
this.state = { dataSource: ds.cloneWithRows(props.data) };
}

static renderRow(title) {
return <RowItem item={{ title }} />
return <RowItem item={{ title }} />;
}

/**
/**
* Render the CustomListView
*/
render() {
return (
<View>
<Title value="Variant ListView" color="#EF5350"/>
<ListView
dataSource={this.state.dataSource}
renderRow={CustomListView.renderRow}
/>
render() {
return (
<View>
<Title value="Variant ListView" color="#EF5350" />
<ListView dataSource={this.state.dataSource} renderRow={CustomListView.renderRow} />
</View>
);
}
}
);
}
}
8 changes: 6 additions & 2 deletions Example/src/RowItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const styles = {
},
};

export default function({ item }) {
return <View><Text style={styles.text}>{item.title}</Text></View>
export default function ({ item }) {
return (
<View>
<Text style={styles.text}>{item.title}</Text>
</View>
);
}
2 changes: 1 addition & 1 deletion Example/src/Title.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default function ({ value, color }) {
<View>
<Text style={style}>{value}</Text>
</View>
)
);
}
2 changes: 1 addition & 1 deletion Example/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export default [
'Shanti Solem',
'Yuri Doughtie',
'Wilford Meredith',
];
];
37 changes: 21 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,37 @@
"version": "0.0.1",
"main": "index.js",
"scripts": {
"format":
"prettier-eslint --write \"src/**/*.js\" && prettier-eslint --write \"Example/src/**/*.js\"",
"lint": "eslint ./src",
"test": "./node_modules/.bin/jest --coverage",
"test": "./node_modules/.bin/jest --coverage --no-cache",
"test:auto": "./node_modules/.bin/jest --watch"
},
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0"
"prop-types": "^15.5.10"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"coveralls": "^2.13.1",
"enzyme": "^2.9.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.6.1",
"eslint-plugin-jsx-a11y": "^5.1.0",
"enzyme": "^3.1.0",
"enzyme-adapter-react-16": "^1.0.2",
"eslint": "^4.1.1",
"eslint-config-airbnb": "^15.0.2",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.1.0",
"jest": "^20.0.0",
"react-native-mock": "^0.3.1",
"react-test-renderer": "16.0.0-alpha.12"
"jest": "21.2.1",
"prettier": "^1.6.1",
"prettier-eslint-cli": "^4.3.0",
"react": "16.0.0-beta.5",
"react-dom": "16.0.0-beta.5",
"react-native": "0.49.3",
"react-test-renderer": "16.0.0-beta.5"
},
"jest": {
"preset": "react-native",
"setupFiles": [
"./setup/test.setup.js"
]
"setupFiles": ["./setup/test.setup.js"],
"modulePathIgnorePatterns": ["<rootDir>/Example/"]
}
}
6 changes: 4 additions & 2 deletions setup/test.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/* eslint-disable */
require('react-native-mock/mock');
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
25 changes: 20 additions & 5 deletions src/__tests__/reactNativeAbHoc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ describe('ReactNativeAbHoc', () => {
const getItem = () => Promise.resolve('A');
jest.setMock('AsyncStorage', { setItem: jest.fn(setItem), getItem: jest.fn(getItem) });

A = () => (<View><Text>A</Text></View>);
B = () => (<View><Text>B</Text></View>);
C = () => (<View><Text>C</Text></View>);
A = () => (
<View>
<Text>A</Text>
</View>
);
B = () => (
<View>
<Text>B</Text>
</View>
);
C = () => (
<View>
<Text>C</Text>
</View>
);

Component = ReactNativeAbHoc('Experiment',
Component = ReactNativeAbHoc(
'Experiment',
{ variant: 'A', component: A },
{ variant: 'B', component: B },
{ variant: 'C', component: C },
Expand All @@ -36,7 +49,9 @@ describe('ReactNativeAbHoc', () => {
});

it('should have thrown an error if the variant variant doesnt exist', () => {
expect(() => shallow(<Component variant="X" />)).toThrow('The variant named "X" doesn\'t exist in the current experient "Experiment');
expect(() => shallow(<Component variant="X" />)).toThrow(
'The variant named "X" doesn\'t exist in the current experient "Experiment',
);
});

it('should have returned the second component', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/reactNativeAbHoc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { View, AsyncStorage } from 'react-native';

const LOCAL_STORAGE_KEY = 'abhoc-variant';
Expand All @@ -8,7 +9,9 @@ export default (experiment, ...variants) => {
static findVariant(variant) {
const chosenVariant = variants.find(v => v.variant === variant);
if (!chosenVariant) {
throw new Error(`The variant named "${variant}" doesn't exist in the current experient "${experiment}"`);
throw new Error(
`The variant named "${variant}" doesn't exist in the current experient "${experiment}"`,
);
}
return chosenVariant;
}
Expand Down Expand Up @@ -56,7 +59,7 @@ export default (experiment, ...variants) => {
}

AbHoc.propTypes = {
variant: React.PropTypes.string,
variant: PropTypes.string,
};

AbHoc.defaultProps = {
Expand Down

0 comments on commit bc75fe2

Please sign in to comment.