Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 66813a4

Browse files
committed
Enable eslint rule: space-before-function-paren
1 parent 8e4c6e3 commit 66813a4

File tree

8 files changed

+49
-50
lines changed

8 files changed

+49
-50
lines changed

.eslintrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"react/jsx-uses-react": "error",
88
"react/jsx-uses-vars": "error",
99
"array-bracket-spacing": 0,
10-
"comma-dangle": 0,
11-
"space-before-function-paren": 0
10+
"comma-dangle": 0
1211
}
1312
}

examples/async-data/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { getStates, styles, fakeRequest } from '../../lib/utils'
55

66
let App = React.createClass({
77

8-
getInitialState () {
8+
getInitialState() {
99
return {
1010
value: '',
1111
unitedStates: getStates(),
1212
loading: false
1313
}
1414
},
1515

16-
render () {
16+
render() {
1717
return (
1818
<div>
1919
<h1>Async Data</h1>

examples/custom-menu/app.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { getStates, styles, fakeRequest } from '../../lib/utils'
55

66
let App = React.createClass({
77

8-
getInitialState () {
8+
getInitialState() {
99
return {
1010
value: '',
1111
unitedStates: getStates(),
1212
loading: false
1313
}
1414
},
1515

16-
render () {
16+
render() {
1717
return (
1818
<div>
1919
<h1>Custom Menu</h1>
@@ -58,7 +58,7 @@ let App = React.createClass({
5858
)
5959
},
6060

61-
renderItems (items) {
61+
renderItems(items) {
6262
return items.map((item, index) => {
6363
const text = item.props.children
6464
if (index === 0 || items[index - 1].props.children.charAt(0) !== text.charAt(0)) {

examples/managed-menu-visibility/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const STATES = getStates()
77

88
class App extends Component {
99

10-
constructor (props) {
10+
constructor(props) {
1111
super(props)
1212
this.state = {
1313
value: '',
@@ -16,7 +16,7 @@ class App extends Component {
1616
}
1717
}
1818

19-
render () {
19+
render() {
2020
const { state } = this
2121
const open = state.forceOpen || state.isOpen
2222
return (

examples/static-data/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let App = React.createClass({
77
getInitialState() {
88
return { value: 'Ma' }
99
},
10-
render () {
10+
render() {
1111
return (
1212
<div>
1313
<h1>Basic Example with Static Data</h1>

lib/Autocomplete.js

+32-32
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ let Autocomplete = React.createClass({
112112
debug: PropTypes.bool,
113113
},
114114

115-
getDefaultProps () {
115+
getDefaultProps() {
116116
return {
117117
value: '',
118118
wrapperProps: {},
119119
wrapperStyle: {
120120
display: 'inline-block'
121121
},
122122
inputProps: {},
123-
onChange () {},
124-
onSelect () {},
125-
renderMenu (items, value, style) {
123+
onChange() {},
124+
onSelect() {},
125+
renderMenu(items, value, style) {
126126
return <div style={{ ...style, ...this.menuStyle }} children={items}/>
127127
},
128128
menuStyle: {
@@ -136,24 +136,24 @@ let Autocomplete = React.createClass({
136136
maxHeight: '50%', // TODO: don't cheat, let it flow to the bottom
137137
},
138138
autoHighlight: true,
139-
onMenuVisibilityChange () {},
139+
onMenuVisibilityChange() {},
140140
}
141141
},
142142

143-
getInitialState () {
143+
getInitialState() {
144144
return {
145145
isOpen: false,
146146
highlightedIndex: null,
147147
}
148148
},
149149

150-
componentWillMount () {
150+
componentWillMount() {
151151
this._ignoreBlur = false
152152
this._performAutoCompleteOnUpdate = false
153153
this._performAutoCompleteOnKeyUp = false
154154
},
155155

156-
componentWillReceiveProps (nextProps) {
156+
componentWillReceiveProps(nextProps) {
157157
this._performAutoCompleteOnUpdate = true
158158
// If `items` has changed we want to reset `highlightedIndex`
159159
// since it probably no longer refers to a relevant item
@@ -166,13 +166,13 @@ let Autocomplete = React.createClass({
166166
}
167167
},
168168

169-
componentDidMount () {
169+
componentDidMount() {
170170
if (this.isOpen()) {
171171
this.setMenuPositions()
172172
}
173173
},
174174

175-
componentDidUpdate (prevProps, prevState) {
175+
componentDidUpdate(prevProps, prevState) {
176176
if ((this.state.isOpen && !prevState.isOpen) || ('open' in this.props && this.props.open && !prevProps.open))
177177
this.setMenuPositions()
178178

@@ -187,7 +187,7 @@ let Autocomplete = React.createClass({
187187
}
188188
},
189189

190-
maybeScrollItemIntoView () {
190+
maybeScrollItemIntoView() {
191191
if (this.isOpen() && this.state.highlightedIndex !== null) {
192192
const itemNode = this.refs[`item-${this.state.highlightedIndex}`]
193193
const menuNode = this.refs.menu
@@ -201,7 +201,7 @@ let Autocomplete = React.createClass({
201201
}
202202
},
203203

204-
handleKeyDown (event) {
204+
handleKeyDown(event) {
205205
if (this.keyDownHandlers[event.key])
206206
this.keyDownHandlers[event.key].call(this, event)
207207
else {
@@ -212,20 +212,20 @@ let Autocomplete = React.createClass({
212212
}
213213
},
214214

215-
handleChange (event) {
215+
handleChange(event) {
216216
this._performAutoCompleteOnKeyUp = true
217217
this.props.onChange(event, event.target.value)
218218
},
219219

220-
handleKeyUp () {
220+
handleKeyUp() {
221221
if (this._performAutoCompleteOnKeyUp) {
222222
this._performAutoCompleteOnKeyUp = false
223223
this.maybeAutoCompleteText()
224224
}
225225
},
226226

227227
keyDownHandlers: {
228-
ArrowDown (event) {
228+
ArrowDown(event) {
229229
event.preventDefault()
230230
const itemsLength = this.getFilteredItems().length
231231
if (!itemsLength) return
@@ -241,7 +241,7 @@ let Autocomplete = React.createClass({
241241
})
242242
},
243243

244-
ArrowUp (event) {
244+
ArrowUp(event) {
245245
event.preventDefault()
246246
const itemsLength = this.getFilteredItems().length
247247
if (!itemsLength) return
@@ -257,7 +257,7 @@ let Autocomplete = React.createClass({
257257
})
258258
},
259259

260-
Enter (event) {
260+
Enter(event) {
261261
if (!this.isOpen()) {
262262
// menu is closed so there is no selection to accept -> do nothing
263263
return
@@ -289,15 +289,15 @@ let Autocomplete = React.createClass({
289289
}
290290
},
291291

292-
Escape () {
292+
Escape() {
293293
this.setState({
294294
highlightedIndex: null,
295295
isOpen: false
296296
})
297297
}
298298
},
299299

300-
getFilteredItems () {
300+
getFilteredItems() {
301301
let items = this.props.items
302302

303303
if (this.props.shouldItemRender) {
@@ -315,7 +315,7 @@ let Autocomplete = React.createClass({
315315
return items
316316
},
317317

318-
maybeAutoCompleteText () {
318+
maybeAutoCompleteText() {
319319
if (!this.props.autoHighlight || this.props.value === '')
320320
return
321321
const { highlightedIndex } = this.state
@@ -332,7 +332,7 @@ let Autocomplete = React.createClass({
332332
this.setState({ highlightedIndex: 0 })
333333
},
334334

335-
setMenuPositions () {
335+
setMenuPositions() {
336336
const node = this.refs.input
337337
const rect = node.getBoundingClientRect()
338338
const computedStyle = global.window.getComputedStyle(node)
@@ -346,11 +346,11 @@ let Autocomplete = React.createClass({
346346
})
347347
},
348348

349-
highlightItemFromMouse (index) {
349+
highlightItemFromMouse(index) {
350350
this.setState({ highlightedIndex: index })
351351
},
352352

353-
selectItemFromMouse (item) {
353+
selectItemFromMouse(item) {
354354
const value = this.props.getItemValue(item)
355355
this.setState({
356356
isOpen: false,
@@ -361,11 +361,11 @@ let Autocomplete = React.createClass({
361361
})
362362
},
363363

364-
setIgnoreBlur (ignore) {
364+
setIgnoreBlur(ignore) {
365365
this._ignoreBlur = ignore
366366
},
367367

368-
renderMenu () {
368+
renderMenu() {
369369
const items = this.getFilteredItems().map((item, index) => {
370370
const element = this.props.renderItem(
371371
item,
@@ -388,7 +388,7 @@ let Autocomplete = React.createClass({
388388
return React.cloneElement(menu, { ref: 'menu' })
389389
},
390390

391-
handleInputBlur () {
391+
handleInputBlur() {
392392
if (this._ignoreBlur)
393393
return
394394
this.setState({
@@ -397,7 +397,7 @@ let Autocomplete = React.createClass({
397397
})
398398
},
399399

400-
handleInputFocus () {
400+
handleInputFocus() {
401401
if (this._ignoreBlur) {
402402
this.setIgnoreBlur(false)
403403
return
@@ -410,12 +410,12 @@ let Autocomplete = React.createClass({
410410
this.setState({ isOpen: true })
411411
},
412412

413-
isInputFocused () {
413+
isInputFocused() {
414414
const el = this.refs.input
415415
return el.ownerDocument && (el === el.ownerDocument.activeElement)
416416
},
417417

418-
handleInputClick () {
418+
handleInputClick() {
419419
// Input will not be focused if it's disabled
420420
if (this.isInputFocused() && !this.isOpen())
421421
this.setState({ isOpen: true })
@@ -424,17 +424,17 @@ let Autocomplete = React.createClass({
424424
this._ignoreClick = false
425425
},
426426

427-
composeEventHandlers (internal, external) {
427+
composeEventHandlers(internal, external) {
428428
return external
429429
? e => { internal(e); external(e) }
430430
: internal
431431
},
432432

433-
isOpen () {
433+
isOpen() {
434434
return 'open' in this.props ? this.props.open : this.state.isOpen
435435
},
436436

437-
render () {
437+
render() {
438438
if (this.props.debug) { // you don't like it, you love it
439439
_debugStates.push({
440440
id: _debugStates.length,

lib/__tests__/Autocomplete-test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { mount } from 'enzyme'
66
import Autocomplete from '../Autocomplete'
77
import { getStates, matchStateToTerm, styles } from '../utils'
88

9-
function AutocompleteComponentJSX (extraProps) {
9+
function AutocompleteComponentJSX(extraProps) {
1010
return (
1111
<Autocomplete
1212
labelText="Choose a state from the US"
@@ -384,20 +384,20 @@ describe('Autocomplete#renderMenu', () => {
384384

385385
it('should allow using custom components', () => {
386386
class Menu extends React.Component {
387-
render () {
387+
render() {
388388
return <div>{this.props.items}</div>
389389
}
390390
}
391391
class Item extends React.Component {
392-
render () {
392+
render() {
393393
return <div>{this.props.item.name}</div>
394394
}
395395
}
396396
const wrapper = mount(AutocompleteComponentJSX({
397-
renderMenu (items) {
397+
renderMenu(items) {
398398
return <Menu items={items} />
399399
},
400-
renderItem (item) {
400+
renderItem(item) {
401401
return <Item key={item.abbr} item={item} />
402402
}
403403
}))

lib/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export let styles = {
1717
}
1818

1919

20-
export function matchStateToTerm (state, value) {
20+
export function matchStateToTerm(state, value) {
2121
return (
2222
state.name.toLowerCase().indexOf(value.toLowerCase()) !== -1 ||
2323
state.abbr.toLowerCase().indexOf(value.toLowerCase()) !== -1
@@ -32,7 +32,7 @@ export function matchStateToTerm (state, value) {
3232
* location (or there is no match) will be sorted alphabetically - For example,
3333
* a search for "or" would return "North Carolina" above "North Dakota".
3434
*/
35-
export function sortStates (a, b, value) {
35+
export function sortStates(a, b, value) {
3636
const aLower = a.name.toLowerCase()
3737
const bLower = b.name.toLowerCase()
3838
const valueLower = value.toLowerCase()
@@ -44,7 +44,7 @@ export function sortStates (a, b, value) {
4444
return aLower < bLower ? -1 : 1
4545
}
4646

47-
export function fakeRequest (value, cb) {
47+
export function fakeRequest(value, cb) {
4848
if (value === '')
4949
return getStates()
5050
const items = getStates().filter((state) => {

0 commit comments

Comments
 (0)