Skip to content

Commit 9f1b61d

Browse files
committed
Add lint rule for consistent spacing before blocks
1 parent a3c370d commit 9f1b61d

File tree

4 files changed

+149
-149
lines changed

4 files changed

+149
-149
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module.exports = {
3030
"semi": 2,
3131
// Enforce consistent spacing before and after semicolons
3232
"semi-spacing": 2,
33+
// Enforce consistent spacing before blocks
34+
"space-before-blocks": 2,
3335
// Enforce consistent spacing inside parentheses
3436
// "space-in-parens": [2, "always"],
3537
// Enforce the consistent use of either backticks, double, or single quotes

DateTime.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

33
var assign = require('object-assign'),
4+
moment = require('moment'),
45
React = require('react'),
56
DaysView = require('./src/DaysView'),
67
MonthsView = require('./src/MonthsView'),
78
YearsView = require('./src/YearsView'),
8-
TimeView = require('./src/TimeView'),
9-
moment = require('moment')
9+
TimeView = require('./src/TimeView')
1010
;
1111

1212
var TYPES = React.PropTypes;
@@ -42,7 +42,7 @@ var Datetime = React.createClass({
4242
},
4343

4444
getDefaultProps: function() {
45-
var nof = function(){};
45+
var nof = function() {};
4646
return {
4747
className: '',
4848
defaultValue: '',
@@ -72,7 +72,7 @@ var Datetime = React.createClass({
7272
return state;
7373
},
7474

75-
getStateFromProps: function( props ){
75+
getStateFromProps: function( props ) {
7676
var formats = this.getFormats( props ),
7777
date = props.value || props.defaultValue,
7878
selectedDate, viewDate, updateOn, inputValue
@@ -110,36 +110,36 @@ var Datetime = React.createClass({
110110
};
111111
},
112112

113-
getUpdateOn: function(formats){
114-
if ( formats.date.match(/[lLD]/) ){
113+
getUpdateOn: function( formats ) {
114+
if ( formats.date.match(/[lLD]/) ) {
115115
return 'days';
116116
}
117-
else if ( formats.date.indexOf('M') !== -1 ){
117+
else if ( formats.date.indexOf('M') !== -1 ) {
118118
return 'months';
119119
}
120-
else if ( formats.date.indexOf('Y') !== -1 ){
120+
else if ( formats.date.indexOf('Y') !== -1 ) {
121121
return 'years';
122122
}
123123

124124
return 'days';
125125
},
126126

127-
getFormats: function( props ){
127+
getFormats: function( props ) {
128128
var formats = {
129129
date: props.dateFormat || '',
130130
time: props.timeFormat || ''
131131
},
132132
locale = this.localMoment( props.date ).localeData()
133133
;
134134

135-
if ( formats.date === true ){
135+
if ( formats.date === true ) {
136136
formats.date = locale.longDateFormat('L');
137137
}
138-
else if ( this.getUpdateOn(formats) !== 'days' ){
138+
else if ( this.getUpdateOn(formats) !== 'days' ) {
139139
formats.time = '';
140140
}
141141

142-
if ( formats.time === true ){
142+
if ( formats.time === true ) {
143143
formats.time = locale.longDateFormat('LT');
144144
}
145145

@@ -151,7 +151,7 @@ var Datetime = React.createClass({
151151
return formats;
152152
},
153153

154-
componentWillReceiveProps: function(nextProps) {
154+
componentWillReceiveProps: function( nextProps ) {
155155
var formats = this.getFormats( nextProps ),
156156
update = {}
157157
;
@@ -161,7 +161,7 @@ var Datetime = React.createClass({
161161
update = this.getStateFromProps( nextProps );
162162
}
163163

164-
if ( update.open === undefined ){
164+
if ( update.open === undefined ) {
165165
update.open = this.state.open;
166166
}
167167

@@ -191,46 +191,46 @@ var Datetime = React.createClass({
191191
});
192192
},
193193

194-
onInputKey: function( e ){
195-
if ( e.which === 9 && this.props.closeOnTab ){
194+
onInputKey: function( e ) {
195+
if ( e.which === 9 && this.props.closeOnTab ) {
196196
this.closeCalendar();
197197
}
198198
},
199199

200-
showView: function( view ){
200+
showView: function( view ) {
201201
var me = this;
202-
return function(){
202+
return function() {
203203
me.setState({ currentView: view });
204204
};
205205
},
206206

207-
setDate: function( type ){
207+
setDate: function( type ) {
208208
var me = this,
209209
nextViews = {
210210
month: 'days',
211211
year: 'months'
212212
}
213213
;
214-
return function( e ){
214+
return function( e ) {
215215
me.setState({
216216
viewDate: me.state.viewDate.clone()[ type ]( parseInt(e.target.getAttribute('data-value'), 10) ).startOf( type ),
217217
currentView: nextViews[ type ]
218218
});
219219
};
220220
},
221221

222-
addTime: function( amount, type, toSelected ){
222+
addTime: function( amount, type, toSelected ) {
223223
return this.updateTime( 'add', amount, type, toSelected );
224224
},
225225

226-
subtractTime: function( amount, type, toSelected ){
226+
subtractTime: function( amount, type, toSelected ) {
227227
return this.updateTime( 'subtract', amount, type, toSelected );
228228
},
229229

230-
updateTime: function( op, amount, type, toSelected ){
230+
updateTime: function( op, amount, type, toSelected ) {
231231
var me = this;
232232

233-
return function(){
233+
return function() {
234234
var update = {},
235235
date = toSelected ? 'selectedDate' : 'viewDate'
236236
;
@@ -242,7 +242,7 @@ var Datetime = React.createClass({
242242
},
243243

244244
allowedSetTime: ['hours', 'minutes', 'seconds', 'milliseconds'],
245-
setTime: function( type, value ){
245+
setTime: function( type, value ) {
246246
var index = this.allowedSetTime.indexOf( type ) + 1,
247247
state = this.state,
248248
date = (state.selectedDate || state.viewDate).clone(),
@@ -257,7 +257,7 @@ var Datetime = React.createClass({
257257
date[ nextType ]( date[nextType]() );
258258
}
259259

260-
if ( !this.props.value ){
260+
if ( !this.props.value ) {
261261
this.setState({
262262
selectedDate: date,
263263
inputValue: date.format( state.inputFormat )
@@ -274,7 +274,7 @@ var Datetime = React.createClass({
274274
date
275275
;
276276

277-
if (target.className.indexOf('rdtDay') !== -1){
277+
if (target.className.indexOf('rdtDay') !== -1) {
278278
if (target.className.indexOf('rdtNew') !== -1)
279279
modifier = 1;
280280
else if (target.className.indexOf('rdtOld') !== -1)
@@ -283,11 +283,11 @@ var Datetime = React.createClass({
283283
date = viewDate.clone()
284284
.month( viewDate.month() + modifier )
285285
.date( parseInt( target.getAttribute('data-value'), 10 ) );
286-
} else if (target.className.indexOf('rdtMonth') !== -1){
286+
} else if (target.className.indexOf('rdtMonth') !== -1) {
287287
date = viewDate.clone()
288288
.month( parseInt( target.getAttribute('data-value'), 10 ) )
289289
.date( currentDate.date() );
290-
} else if (target.className.indexOf('rdtYear') !== -1){
290+
} else if (target.className.indexOf('rdtYear') !== -1) {
291291
date = viewDate.clone()
292292
.month( currentDate.month() )
293293
.date( currentDate.date() )
@@ -299,7 +299,7 @@ var Datetime = React.createClass({
299299
.seconds( currentDate.seconds() )
300300
.milliseconds( currentDate.milliseconds() );
301301

302-
if ( !this.props.value ){
302+
if ( !this.props.value ) {
303303
this.setState({
304304
selectedDate: date,
305305
viewDate: date.clone().startOf('month'),
@@ -329,15 +329,15 @@ var Datetime = React.createClass({
329329
});
330330
},
331331

332-
handleClickOutside: function(){
333-
if ( this.props.input && this.state.open && !this.props.open ){
332+
handleClickOutside: function() {
333+
if ( this.props.input && this.state.open && !this.props.open ) {
334334
this.setState({ open: false }, function() {
335335
this.props.onBlur( this.state.selectedDate || this.state.inputValue );
336336
});
337337
}
338338
},
339339

340-
localMoment: function( date, format ){
340+
localMoment: function( date, format ) {
341341
var momentFn = this.props.utc ? moment.utc : moment;
342342
var m = momentFn( date, format, this.props.strictParsing );
343343
if ( this.props.locale )
@@ -351,19 +351,19 @@ var Datetime = React.createClass({
351351
fromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment']
352352
},
353353

354-
getComponentProps: function(){
354+
getComponentProps: function() {
355355
var me = this,
356356
formats = this.getFormats( this.props ),
357357
props = {dateFormat: formats.date, timeFormat: formats.time}
358358
;
359359

360-
this.componentProps.fromProps.forEach( function( name ){
360+
this.componentProps.fromProps.forEach( function( name ) {
361361
props[ name ] = me.props[ name ];
362362
});
363-
this.componentProps.fromState.forEach( function( name ){
363+
this.componentProps.fromState.forEach( function( name ) {
364364
props[ name ] = me.state[ name ];
365365
});
366-
this.componentProps.fromThis.forEach( function( name ){
366+
this.componentProps.fromThis.forEach( function( name ) {
367367
props[ name ] = me[ name ];
368368
});
369369

@@ -379,10 +379,10 @@ var Datetime = React.createClass({
379379
children = []
380380
;
381381

382-
if ( this.props.input ){
382+
if ( this.props.input ) {
383383
children = [ DOM.input( assign({
384384
key: 'i',
385-
type:'text',
385+
type: 'text',
386386
className: 'form-control',
387387
onFocus: this.openCalendar,
388388
onChange: this.onInputChange,

src/DaysView.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var DateTimePickerDays = React.createClass({
2020
DOM.th({ key: 's', className: 'rdtSwitch', onClick: this.props.showView( 'months' ), colSpan: 5, 'data-value': this.props.viewDate.month() }, locale.months( date ) + ' ' + date.year() ),
2121
DOM.th({ key: 'n', className: 'rdtNext' }, DOM.span({ onClick: this.props.addTime( 1, 'months' )}, '›' ))
2222
]),
23-
DOM.tr({ key: 'd'}, this.getDaysOfWeek( locale ).map( function( day, index ){ return DOM.th({ key: day + index, className: 'dow'}, day ); }) )
23+
DOM.tr({ key: 'd'}, this.getDaysOfWeek( locale ).map( function( day, index ) { return DOM.th({ key: day + index, className: 'dow'}, day ); }) )
2424
]),
2525
DOM.tbody({ key: 'tb' }, this.renderDays())
2626
];
@@ -130,6 +130,7 @@ var DateTimePickerDays = React.createClass({
130130
)
131131
);
132132
},
133+
133134
alwaysValidDate: function() {
134135
return 1;
135136
}

0 commit comments

Comments
 (0)