From 41ae9c32c2c81b1bb6139425d53b747065ee8509 Mon Sep 17 00:00:00 2001 From: Andrew Ingram Date: Wed, 13 May 2015 11:25:48 +0100 Subject: [PATCH] fix the lints --- dist/DateRangePicker.js | 20 +++++--------- dist/calendar/CalendarDate.js | 4 --- dist/calendar/CalendarDatePeriod.js | 5 ++++ dist/calendar/CalendarHighlight.js | 4 +++ dist/calendar/CalendarMonth.js | 18 +++++++++++-- dist/calendar/CalendarSelection.js | 5 ++++ dist/utils/BemMixin.js | 3 ++- dist/utils/CustomPropTypes.js | 42 +++++++++++++++++++++++++++++ dist/utils/bemCx.js | 4 +-- dist/utils/shallowEqual.js | 9 ++++++- src/DateRangePicker.jsx | 27 ++++++------------- src/calendar/CalendarDate.jsx | 4 +-- src/calendar/CalendarDatePeriod.jsx | 7 ++++- src/calendar/CalendarHighlight.jsx | 4 +++ src/calendar/CalendarMonth.jsx | 23 +++++++++++++--- src/calendar/CalendarSelection.jsx | 5 ++++ src/utils/BemMixin.js | 4 +-- src/utils/CustomPropTypes.js | 41 ++++++++++++++++++++++++++++ src/utils/PureRenderMixin.js | 2 +- src/utils/bemCx.js | 6 ++--- src/utils/lightenDarkenColor.js | 4 +-- src/utils/shallowEqual.js | 4 ++- 22 files changed, 186 insertions(+), 59 deletions(-) create mode 100644 dist/utils/CustomPropTypes.js create mode 100644 src/utils/CustomPropTypes.js diff --git a/dist/DateRangePicker.js b/dist/DateRangePicker.js index 409ab7d6..6fbf6cd1 100644 --- a/dist/DateRangePicker.js +++ b/dist/DateRangePicker.js @@ -26,6 +26,10 @@ var _utilsBemMixin = require('./utils/BemMixin'); var _utilsBemMixin2 = _interopRequireDefault(_utilsBemMixin); +var _utilsCustomPropTypes = require('./utils/CustomPropTypes'); + +var _utilsCustomPropTypes2 = _interopRequireDefault(_utilsCustomPropTypes); + var _Legend = require('./Legend'); var _Legend2 = _interopRequireDefault(_Legend); @@ -85,18 +89,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({ selectionType: _reactAddons2['default'].PropTypes.oneOf(['single', 'range']), showLegend: _reactAddons2['default'].PropTypes.bool, stateDefinitions: _reactAddons2['default'].PropTypes.object, - value: function value(props, propName) { - var val = props[propName]; - - if (!val) { - return null; - } else if (_momentRange2['default'].isMoment(val)) { - return null; - } else if (val.start && val.end && _momentRange2['default'].isMoment(val.start) && _momentRange2['default'].isMoment(val.end)) { - return null; - } - return new Error('Value must be a moment or a moment range'); - } + value: _utilsCustomPropTypes2['default'].momentOrMomentRange }, getDefaultProps: function getDefaultProps() { @@ -301,7 +294,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({ } }, - onUnHighlightDate: function onUnHighlightDate(date) { + onUnHighlightDate: function onUnHighlightDate() { this.setState({ highlightedDate: null }); @@ -508,7 +501,6 @@ var DateRangePicker = _reactAddons2['default'].createClass({ var hideSelection = _state2.hideSelection; var highlightedDate = _state2.highlightedDate; var highlightedRange = _state2.highlightedRange; - var highlightStartDate = _state2.highlightStartDate; var monthDate = this.getMonthDate(); var year = monthDate.year(); diff --git a/dist/calendar/CalendarDate.js b/dist/calendar/CalendarDate.js index 4a99cffd..3538830f 100644 --- a/dist/calendar/CalendarDate.js +++ b/dist/calendar/CalendarDate.js @@ -10,10 +10,6 @@ var _reactAddons = require('react/addons'); var _reactAddons2 = _interopRequireDefault(_reactAddons); -var _momentRange = require('moment-range'); - -var _momentRange2 = _interopRequireDefault(_momentRange); - var _immutable = require('immutable'); var _immutable2 = _interopRequireDefault(_immutable); diff --git a/dist/calendar/CalendarDatePeriod.js b/dist/calendar/CalendarDatePeriod.js index 7f876a06..f4e63e9a 100644 --- a/dist/calendar/CalendarDatePeriod.js +++ b/dist/calendar/CalendarDatePeriod.js @@ -27,6 +27,11 @@ var CalendarDatePeriod = _reactAddons2['default'].createClass({ mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']], + propTypes: { + color: _reactAddons2['default'].PropTypes.string, + period: _reactAddons2['default'].PropTypes.string + }, + render: function render() { var _props = this.props; var color = _props.color; diff --git a/dist/calendar/CalendarHighlight.js b/dist/calendar/CalendarHighlight.js index 60280f22..f7392008 100644 --- a/dist/calendar/CalendarHighlight.js +++ b/dist/calendar/CalendarHighlight.js @@ -27,6 +27,10 @@ var CalendarHighlight = _reactAddons2['default'].createClass({ mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']], + propTypes: { + modifier: _reactAddons2['default'].PropTypes.string + }, + render: function render() { var modifier = this.props.modifier; diff --git a/dist/calendar/CalendarMonth.js b/dist/calendar/CalendarMonth.js index 0621e1d9..76109961 100644 --- a/dist/calendar/CalendarMonth.js +++ b/dist/calendar/CalendarMonth.js @@ -30,6 +30,10 @@ var _utilsBemMixin = require('../utils/BemMixin'); var _utilsBemMixin2 = _interopRequireDefault(_utilsBemMixin); +var _utilsCustomPropTypes = require('../utils/CustomPropTypes'); + +var _utilsCustomPropTypes2 = _interopRequireDefault(_utilsCustomPropTypes); + var _utilsIsMomentRange = require('../utils/isMomentRange'); var _utilsIsMomentRange2 = _interopRequireDefault(_utilsIsMomentRange); @@ -50,6 +54,16 @@ var CalendarMonth = _reactAddons2['default'].createClass({ mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']], + propTypes: { + dateComponent: _reactAddons2['default'].PropTypes.func, + enabledRange: _utilsCustomPropTypes2['default'].momentRange, + firstOfWeek: _reactAddons2['default'].PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]), + hideSelection: _reactAddons2['default'].PropTypes.bool, + highlightedDate: _reactAddons2['default'].PropTypes.object, + highlightedRange: _reactAddons2['default'].PropTypes.object, + value: _utilsCustomPropTypes2['default'].momentOrMomentRange + }, + renderDay: function renderDay(date, i) { var _props = this.props; var CalendarDate = _props.dateComponent; @@ -137,11 +151,11 @@ var CalendarMonth = _reactAddons2['default'].createClass({ var enabledRange = this.props.enabledRange; if (year < enabledRange.start.year()) { - return; + return null; } if (year > enabledRange.end.year()) { - return; + return null; } return _reactAddons2['default'].createElement( diff --git a/dist/calendar/CalendarSelection.js b/dist/calendar/CalendarSelection.js index d87d9df1..ea829799 100644 --- a/dist/calendar/CalendarSelection.js +++ b/dist/calendar/CalendarSelection.js @@ -27,6 +27,11 @@ var CalendarSelection = _reactAddons2['default'].createClass({ mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']], + propTypes: { + modifier: _reactAddons2['default'].PropTypes.string, + pending: _reactAddons2['default'].PropTypes.bool.isRequired + }, + render: function render() { var _props = this.props; var modifier = _props.modifier; diff --git a/dist/utils/BemMixin.js b/dist/utils/BemMixin.js index d7d2ab53..a681fe3a 100644 --- a/dist/utils/BemMixin.js +++ b/dist/utils/BemMixin.js @@ -65,7 +65,8 @@ var BemMixin = { var opts = { namespace: this.getBemNamespace(), element: this.constructor.displayName, - block: this.getBemBlock() }; + block: this.getBemBlock() + }; _extends(opts, options); return _bemCx2['default'](opts); diff --git a/dist/utils/CustomPropTypes.js b/dist/utils/CustomPropTypes.js new file mode 100644 index 00000000..e63155c1 --- /dev/null +++ b/dist/utils/CustomPropTypes.js @@ -0,0 +1,42 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _momentRange = require('moment-range'); + +var _momentRange2 = _interopRequireDefault(_momentRange); + +var _isMomentRange = require('./isMomentRange'); + +var _isMomentRange2 = _interopRequireDefault(_isMomentRange); + +exports['default'] = { + momentOrMomentRange: function momentOrMomentRange(props, propName) { + var val = props[propName]; + + if (!val) { + return null; + } else if (_momentRange2['default'].isMoment(val)) { + return null; + } else if (_isMomentRange2['default'](val)) { + return null; + } + return new Error('Value must be a moment or a moment range'); + }, + + momentRange: function momentRange(props, propName) { + var val = props[propName]; + + if (!val) { + return null; + } else if (_isMomentRange2['default'](val)) { + return null; + } + return new Error('Value must be a moment range'); + } +}; +module.exports = exports['default']; \ No newline at end of file diff --git a/dist/utils/bemCx.js b/dist/utils/bemCx.js index 0ab81964..e12371a3 100644 --- a/dist/utils/bemCx.js +++ b/dist/utils/bemCx.js @@ -33,7 +33,7 @@ function bemCx() { bemClasses.push(baseClassName); if (states) { - if (typeof states == 'object') { + if (typeof states === 'object') { states = Object.keys(states).filter(function (s) { return states[s]; }); @@ -45,7 +45,7 @@ function bemCx() { } if (modifiers) { - if (typeof modifiers == 'object') { + if (typeof modifiers === 'object') { modifiers = Object.keys(modifiers).filter(function (m) { return modifiers[m]; }); diff --git a/dist/utils/shallowEqual.js b/dist/utils/shallowEqual.js index 4db861a7..d846340a 100644 --- a/dist/utils/shallowEqual.js +++ b/dist/utils/shallowEqual.js @@ -1,5 +1,9 @@ 'use strict'; +Object.defineProperty(exports, '__esModule', { + value: true +}); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _momentRange = require('moment-range'); @@ -19,6 +23,7 @@ function shallowEqual(objA, objB) { return true; } var key; + // Test for A's keys different from B. for (key in objA) { if (objA.hasOwnProperty(key)) { @@ -35,6 +40,7 @@ function shallowEqual(objA, objB) { } } } + // Test for B's keys missing from A. for (key in objB) { if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) { @@ -44,4 +50,5 @@ function shallowEqual(objA, objB) { return true; } -module.exports = shallowEqual; \ No newline at end of file +exports['default'] = shallowEqual; +module.exports = exports['default']; \ No newline at end of file diff --git a/src/DateRangePicker.jsx b/src/DateRangePicker.jsx index 45f77899..30b4671f 100644 --- a/src/DateRangePicker.jsx +++ b/src/DateRangePicker.jsx @@ -5,6 +5,7 @@ import Immutable from 'immutable'; import calendar from 'calendar'; import BemMixin from './utils/BemMixin'; +import CustomPropTypes from './utils/CustomPropTypes'; import Legend from './Legend'; import CalendarMonth from './calendar/CalendarMonth'; @@ -50,18 +51,7 @@ const DateRangePicker = React.createClass({ selectionType: React.PropTypes.oneOf(['single', 'range']), showLegend: React.PropTypes.bool, stateDefinitions: React.PropTypes.object, - value(props, propName) { - let val = props[propName]; - - if (!val) { - return null; - } else if (moment.isMoment(val)) { - return null; - } else if (val.start && val.end && moment.isMoment(val.start) && moment.isMoment(val.end)) { - return null; - } - return new Error('Value must be a moment or a moment range'); - } + value: CustomPropTypes.momentOrMomentRange }, getDefaultProps() { @@ -252,11 +242,11 @@ const DateRangePicker = React.createClass({ } }, - onUnHighlightDate(date) { + onUnHighlightDate() { this.setState({ highlightedDate: null }); - }, + }, onSelectDate(date) { let {selectionType} = this.props; @@ -298,7 +288,7 @@ const DateRangePicker = React.createClass({ this.highlightDate(date); } } - }, + }, startRangeSelection(date) { this.setState({ @@ -448,8 +438,7 @@ const DateRangePicker = React.createClass({ enabledRange, hideSelection, highlightedDate, - highlightedRange, - highlightStartDate + highlightedRange } = this.state; let monthDate = this.getMonthDate(); @@ -473,7 +462,7 @@ const DateRangePicker = React.createClass({ } else if (isMomentRange(value)) { if (!monthRange.overlaps(value)) { value = null; - } + } } if (!moment.isMoment(highlightedDate) || !monthRange.contains(highlightedDate)) { @@ -482,7 +471,7 @@ const DateRangePicker = React.createClass({ if (!isMomentRange(highlightedRange) || !monthRange.overlaps(highlightedRange)) { highlightedRange = null; - } + } props = { bemBlock, diff --git a/src/calendar/CalendarDate.jsx b/src/calendar/CalendarDate.jsx index 13709eaa..322f5c87 100644 --- a/src/calendar/CalendarDate.jsx +++ b/src/calendar/CalendarDate.jsx @@ -2,10 +2,10 @@ import React from 'react/addons'; -import moment from 'moment-range'; import Immutable from 'immutable'; import BemMixin from '../utils/BemMixin'; +import CustomPropTypes from '../utils/CustomPropTypes'; import PureRenderMixin from '../utils/PureRenderMixin'; import lightenDarkenColor from '../utils/lightenDarkenColor'; @@ -18,7 +18,7 @@ const CalendarDate = React.createClass({ mixins: [BemMixin, PureRenderMixin], propTypes: { - date: React.PropTypes.object.isRequired, + date: CustomPropTypes.moment, firstOfMonth: React.PropTypes.object.isRequired, diff --git a/src/calendar/CalendarDatePeriod.jsx b/src/calendar/CalendarDatePeriod.jsx index 5d7ca630..5460dceb 100644 --- a/src/calendar/CalendarDatePeriod.jsx +++ b/src/calendar/CalendarDatePeriod.jsx @@ -8,13 +8,18 @@ import PureRenderMixin from '../utils/PureRenderMixin'; const CalendarDatePeriod = React.createClass({ mixins: [BemMixin, PureRenderMixin], + propTypes: { + color: React.PropTypes.string, + period: React.PropTypes.string + }, + render() { let {color, period} = this.props; let modifiers = {[period]: true}; let style; if (color) { - style= {backgroundColor: color}; + style = {backgroundColor: color}; } return ( diff --git a/src/calendar/CalendarHighlight.jsx b/src/calendar/CalendarHighlight.jsx index f824d548..ffec9351 100644 --- a/src/calendar/CalendarHighlight.jsx +++ b/src/calendar/CalendarHighlight.jsx @@ -8,6 +8,10 @@ import PureRenderMixin from '../utils/PureRenderMixin'; const CalendarHighlight = React.createClass({ mixins: [BemMixin, PureRenderMixin], + propTypes: { + modifier: React.PropTypes.string + }, + render() { let {modifier} = this.props; let modifiers = {[modifier]: true}; diff --git a/src/calendar/CalendarMonth.jsx b/src/calendar/CalendarMonth.jsx index b8093f2d..e9402b31 100644 --- a/src/calendar/CalendarMonth.jsx +++ b/src/calendar/CalendarMonth.jsx @@ -6,6 +6,7 @@ import calendar from 'calendar'; import Immutable from 'immutable'; import BemMixin from '../utils/BemMixin'; +import CustomPropTypes from '../utils/CustomPropTypes'; import isMomentRange from '../utils/isMomentRange'; import PureRenderMixin from '../utils/PureRenderMixin'; @@ -18,6 +19,20 @@ const MONTHS = Immutable.List(lang._months); const CalendarMonth = React.createClass({ mixins: [BemMixin, PureRenderMixin], + propTypes: { + dateComponent: React.PropTypes.func, + disableNavigation: React.PropTypes.bool, + enabledRange: CustomPropTypes.momentRange, + firstOfMonth: CustomPropTypes.moment, + firstOfWeek: React.PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]), + hideSelection: React.PropTypes.bool, + highlightedDate: React.PropTypes.object, + highlightedRange: React.PropTypes.object, + onMonthChange: React.PropTypes.func, + onYearChange: React.PropTypes.func, + value: CustomPropTypes.momentOrMomentRange + }, + renderDay(date, i) { let {dateComponent: CalendarDate, value, highlightedDate, highlightedRange, hideSelection, enabledRange, ...props} = this.props; let d = moment(date); @@ -86,12 +101,12 @@ const CalendarMonth = React.createClass({ renderYearChoice(year) { let {enabledRange} = this.props; - if (year < enabledRange.start.year()) { - return; + if (year < enabledRange.start.year()) { + return null; } if (year > enabledRange.end.year()) { - return; + return null; } return ( @@ -118,7 +133,7 @@ const CalendarMonth = React.createClass({ this.props.onMonthChange(parseInt(event.target.value, 10)); }, - renderMonthChoice(month , i) { + renderMonthChoice(month, i) { let {firstOfMonth, enabledRange} = this.props; let disabled = false; let year = firstOfMonth.year(); diff --git a/src/calendar/CalendarSelection.jsx b/src/calendar/CalendarSelection.jsx index 41bad696..d85a11ca 100644 --- a/src/calendar/CalendarSelection.jsx +++ b/src/calendar/CalendarSelection.jsx @@ -8,6 +8,11 @@ import PureRenderMixin from '../utils/PureRenderMixin'; const CalendarSelection = React.createClass({ mixins: [BemMixin, PureRenderMixin], + propTypes: { + modifier: React.PropTypes.string, + pending: React.PropTypes.bool.isRequired + }, + render() { let {modifier, pending} = this.props; let modifiers = {[modifier]: true}; diff --git a/src/utils/BemMixin.js b/src/utils/BemMixin.js index 3207330d..2d048c48 100644 --- a/src/utils/BemMixin.js +++ b/src/utils/BemMixin.js @@ -49,7 +49,7 @@ const BemMixin = { let opts = { namespace: this.getBemNamespace(), element: this.constructor.displayName, - block: this.getBemBlock(), + block: this.getBemBlock() }; Object.assign(opts, options); @@ -57,4 +57,4 @@ const BemMixin = { } }; -export default BemMixin; \ No newline at end of file +export default BemMixin; diff --git a/src/utils/CustomPropTypes.js b/src/utils/CustomPropTypes.js new file mode 100644 index 00000000..460a96ec --- /dev/null +++ b/src/utils/CustomPropTypes.js @@ -0,0 +1,41 @@ +import moment from 'moment-range'; + +import isMomentRange from './isMomentRange'; + + +export default { + momentOrMomentRange(props, propName) { + let val = props[propName]; + + if (!val) { + return null; + } else if (moment.isMoment(val)) { + return null; + } else if (isMomentRange(val)) { + return null; + } + return new Error('Value must be a moment or a moment range'); + }, + + moment(props, propName) { + let val = props[propName]; + + if (!val) { + return null; + } else if (moment.isMoment(val)) { + return null; + } + return new Error('Value must be a moment'); + }, + + momentRange(props, propName) { + let val = props[propName]; + + if (!val) { + return null; + } else if (isMomentRange(val)) { + return null; + } + return new Error('Value must be a moment range'); + } +}; diff --git a/src/utils/PureRenderMixin.js b/src/utils/PureRenderMixin.js index 8ed08a0b..85cf5e6c 100644 --- a/src/utils/PureRenderMixin.js +++ b/src/utils/PureRenderMixin.js @@ -10,4 +10,4 @@ const PureRenderMixin = { } }; -export default PureRenderMixin; \ No newline at end of file +export default PureRenderMixin; diff --git a/src/utils/bemCx.js b/src/utils/bemCx.js index b83cc65c..9ce30281 100644 --- a/src/utils/bemCx.js +++ b/src/utils/bemCx.js @@ -20,7 +20,7 @@ export default function bemCx(options={}) { bemClasses.push(baseClassName); if (states) { - if (typeof states == 'object') { + if (typeof states === 'object') { states = Object.keys(states).filter(s => states[s]); } @@ -30,7 +30,7 @@ export default function bemCx(options={}) { } if (modifiers) { - if (typeof modifiers == 'object') { + if (typeof modifiers === 'object') { modifiers = Object.keys(modifiers).filter(m => modifiers[m]); } @@ -46,4 +46,4 @@ export default function bemCx(options={}) { } return bemClasses.join(' '); -} \ No newline at end of file +} diff --git a/src/utils/lightenDarkenColor.js b/src/utils/lightenDarkenColor.js index 74db9632..534f14e5 100644 --- a/src/utils/lightenDarkenColor.js +++ b/src/utils/lightenDarkenColor.js @@ -1,4 +1,4 @@ -export default function lightenDarkenColor(col,amt) { +export default function lightenDarkenColor(col, amt) { let usePound = false; let num; let r; @@ -37,4 +37,4 @@ export default function lightenDarkenColor(col,amt) { } return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16); -} \ No newline at end of file +} diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js index dac93c5d..745245c0 100644 --- a/src/utils/shallowEqual.js +++ b/src/utils/shallowEqual.js @@ -9,6 +9,7 @@ function shallowEqual(objA, objB) { return true; } var key; + // Test for A's keys different from B. for (key in objA) { if (objA.hasOwnProperty(key)) { @@ -32,6 +33,7 @@ function shallowEqual(objA, objB) { } } } + // Test for B's keys missing from A. for (key in objB) { if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) { @@ -41,4 +43,4 @@ function shallowEqual(objA, objB) { return true; } -module.exports = shallowEqual; +export default shallowEqual;