JS style: Arrow functions

Pick up the following style rules

arrow-body-style
arrow-parens
arrow-spacing
prefer-arrow-callback
This commit is contained in:
Erik Arvidsson
2016-01-20 15:45:21 -08:00
parent 7a99c816b9
commit 4d253ae435
11 changed files with 34 additions and 55 deletions

View File

@@ -147,9 +147,8 @@ export default class DataManager {
this._timeSetP, this._categorySetP]);
const store = this._store;
const getAmountRaised = (r: Ref): Promise<number> => {
return readValue(r, store).then(round => round.get('RaisedAmountUsd'));
};
const getAmountRaised = (r: Ref): Promise<number> =>
readValue(r, store).then(round => round.get('RaisedAmountUsd'));
const [seedData, seriesAData, seriesBData] = await Promise.all([
seedSet.intersect(categorySet, timeSet).then(set => set.map(getAmountRaised)),

View File

@@ -10,10 +10,8 @@ type Props<T> = {
export default function List<T>(props: Props<T>) : React.Element {
const delegate = props.delegate;
const labels = props.items.map(item => {
return <Label key={delegate.getLabel(item)} item={item}
delegate={delegate}/>;
});
const labels = props.items.map(item =>
<Label key={delegate.getLabel(item)} item={item} delegate={delegate}/>);
return <div className='selection-list'>
{props.title ? <h3>{props.title}</h3> : null}
{labels}

View File

@@ -93,12 +93,8 @@ class Main extends React.Component<void, Props, State> {
getLabel(item: string): string {
return item;
},
isSelected: (item: string) => {
return this.state.selectedSeries.has(item);
},
getColor: (item: string) => {
return this.props.color[this.props.series.indexOf(item)];
},
isSelected: (item: string) => this.state.selectedSeries.has(item),
getColor: (item: string) => this.props.color[this.props.series.indexOf(item)],
onChange: (item: string) => {
const selectedSeries = new Set(this.state.selectedSeries);
if (selectedSeries.has(item)) {
@@ -114,9 +110,7 @@ class Main extends React.Component<void, Props, State> {
getLabel(item: LabelAndKey): string {
return item.label;
},
isSelected: (item: LabelAndKey) => {
return item === this.state.selectedTimeItem;
},
isSelected: (item: LabelAndKey) => item === this.state.selectedTimeItem,
onChange: (item: LabelAndKey) => {
this._selectedTimeChanged(item);
},
@@ -126,9 +120,7 @@ class Main extends React.Component<void, Props, State> {
getLabel(item: string): string {
return item;
},
isSelected: (item: string) => {
return item === this.state.selectedCategoryItem;
},
isSelected: (item: string) => item === this.state.selectedCategoryItem,
onChange: (item: string) => {
this._selectedCategoryChanged(item);
},

View File

@@ -91,19 +91,15 @@ export default class HeatMap extends React.Component<void, Props, State> {
}
getPoints(): Array<any> {
return this.state.pointList.map(p => {
return <div style={
{
position: 'absolute',
left: p.x,
top: p.y,
background: 'rgba(0,255,0,0.4)',
width: '2px',
height: '2px',
boxShadow: '0px 0px 16px 16px rgba(0,255,0,0.4)',
borderRadius: '50%',
}
}/>;
});
return this.state.pointList.map(p => <div style={{
position: 'absolute',
left: p.x,
top: p.y,
background: 'rgba(0,255,0,0.4)',
width: '2px',
height: '2px',
boxShadow: '0px 0px 16px 16px rgba(0,255,0,0.4)',
borderRadius: '50%',
}}/>);
}
}

View File

@@ -63,9 +63,7 @@ class PitcherList extends React.Component<void, Props, State> {
return <div>
<select onChange={onChangePitcher} defaultValue={currentPitcher}>{
this.props.pitchers.map(pitcher => {
return <option key={pitcher} value={pitcher}>{pitcher}</option>;
})
this.props.pitchers.map(pitcher => <option key={pitcher} value={pitcher}>{pitcher}</option>)
}</select>
<HeatMap key={currentPitcher} pitchListRefP={pitchListRefP} httpStore={httpStore}/>
</div>;

View File

@@ -74,9 +74,7 @@ export default class Photo extends React.Component<DefaultProps, Props, State> {
const sizes = this.state.sizes;
const w = this.props.style.width || 0;
const h = this.props.style.height || 0;
const size = sizes.find(({size}) => {
return size.get('Width') >= w && size.get('Height') >= h;
});
const size = sizes.find(({size}) => size.get('Width') >= w && size.get('Height') >= h);
return size ? size.url : sizes[sizes.length - 1].url;
}
}

View File

@@ -23,14 +23,12 @@ function handleChange(props: Props, tag: string) {
export default function TagList(props: Props) : React.Element {
const tags = [...props.tags].sort();
const labels = tags.map(tag => {
return <label style={tagStyle} key={tag}>
<input type="checkbox" name="tc"
checked={props.selected.has(tag)}
onChange={() => handleChange(props, tag) }/>
{tag}
</label>;
});
const labels = tags.map(tag => <label style={tagStyle} key={tag}>
<input type="checkbox" name="tc"
checked={props.selected.has(tag)}
onChange={() => handleChange(props, tag) }/>
{tag}
</label>);
return <div>{labels}</div>;
}

View File

@@ -2,6 +2,9 @@
"parser": "babel-eslint",
"rules": {
"array-bracket-spacing": [2, "never"],
"arrow-body-style": [2, "as-needed"],
"arrow-parens": 0,
"arrow-spacing": [2, { "before": true, "after": true }],
"camelcase": 2,
"comma-dangle": [2, "always-multiline"],
"eqeqeq": 2,
@@ -13,14 +16,15 @@
"no-throw-literal": 2,
"no-var": 2,
"object-curly-spacing": [2, "never"],
"prefer-arrow-callback": 2,
"prefer-const": 2,
"quotes": [2, "single"],
"radix": 2,
"semi": 2,
"space-after-keywords": 2,
"space-before-function-paren": 0,
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-in-parens": [2, "never"]
},
"env": {
"es6": true,

View File

@@ -3,7 +3,7 @@
import {test as mtest} from 'mocha';
export default function test(n: string, f: () => ?Promise) {
mtest(n, done => {
mtest(n, (done) => {
try {
const p = f();
if (p instanceof Promise) {

View File

@@ -25,9 +25,7 @@ export class IndexedSequence<T> extends Sequence<T> {
export class IndexedSequenceCursor<T> extends SequenceCursor<T, IndexedSequence> {
advanceToOffset(idx: number): number {
this.idx = search(this.length, (i: number) => {
return idx <= this.sequence.getOffset(i);
});
this.idx = search(this.length, (i: number) => idx <= this.sequence.getOffset(i));
if (this.idx === this.length) {
this.idx = this.length - 1;

View File

@@ -46,9 +46,7 @@ export class OrderedSequenceCursor<T, K: valueOrPrimitive> extends
// Moves the cursor to the first value in sequence >= key and returns true.
// If none exists, returns false.
_seekTo(key: K): boolean {
this.idx = search(this.length, (i: number) => {
return !less(this.sequence.getKey(i), key);
});
this.idx = search(this.length, (i: number) => !less(this.sequence.getKey(i), key));
return this.idx < this.length;
}