Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using prettier for formatting #809

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

"extends": [
"airbnb",
"plugin:react-with-styles/recommended"
"plugin:react-with-styles/recommended",
"prettier"
],

"plugins": [
"prettier",
"react-with-styles"
],

Expand All @@ -16,16 +18,18 @@
},

"rules": {
"no-mixed-operators": [2, { "allowSamePrecedence": true }],
"no-mixed-operators": [0, { "allowSamePrecedence": true }],

"jsx-a11y/click-events-have-key-events": 1, // TODO: enable

"react/no-did-mount-set-state": 0, // necessary for server-rendering

"react-with-styles/no-unused-styles": 2
"react-with-styles/no-unused-styles": 2,

"prettier/prettier": [2, {"trailingComma": "all", "singleQuote": true}]
},

"settings": {
"propWrapperFunctions": ["forbidExtraProps", "exact", "Object.freeze"]
"propWrapperFunctions": ["forbidExtraProps", "exact", "Object.freeze"]
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@
"enzyme-adapter-react-15": "^1.0.2",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.6.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-prettier": "^2.3.1",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-react-with-styles": "^1.1.1",
"git-directory-deploy": "^1.5.1",
Expand All @@ -94,6 +96,7 @@
"moment-jalaali": "^0.7.2",
"node-sass": "^4.5.3",
"nyc": "^11.2.1",
"prettier": "^1.7.4",
"raw-loader": "^0.5.1",
"react": "^0.14 || ^15.5.4",
"react-addons-shallow-compare": "^0.14 || ^15.5.2",
Expand Down
60 changes: 33 additions & 27 deletions src/components/CalendarDay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ class CalendarDay extends React.Component {
renderDay,
tabIndex,
styles,
phrases: {
chooseAvailableDate,
dateIsUnavailable,
},
phrases: { chooseAvailableDate, dateIsUnavailable },
} = this.props;

if (!day) return <td />;

const formattedDate = { date: `${day.format('dddd')}, ${day.format('LL')}` };
const formattedDate = {
date: `${day.format('dddd')}, ${day.format('LL')}`,
};

const ariaLabel = modifiers.has(BLOCKED_MODIFIER)
? getPhrase(dateIsUnavailable, formattedDate)
Expand All @@ -112,22 +111,19 @@ class CalendarDay extends React.Component {
height: daySize - 1,
};

const useDefaultCursor = (
modifiers.has('blocked-minimum-nights')
|| modifiers.has('blocked-calendar')
|| modifiers.has('blocked-out-of-range')
);
const useDefaultCursor =
modifiers.has('blocked-minimum-nights') ||
modifiers.has('blocked-calendar') ||
modifiers.has('blocked-out-of-range');

const selected = (
modifiers.has('selected')
|| modifiers.has('selected-start')
|| modifiers.has('selected-end')
);
const selected =
modifiers.has('selected') ||
modifiers.has('selected-start') ||
modifiers.has('selected-end');

const hoveredSpan = !selected && (
modifiers.has('hovered-span')
|| modifiers.has('after-hovered-start')
);
const hoveredSpan =
!selected &&
(modifiers.has('hovered-span') || modifiers.has('after-hovered-start'));

const isOutsideRange = modifiers.has('blocked-out-of-range');

Expand All @@ -136,9 +132,12 @@ class CalendarDay extends React.Component {
{...css(
styles.CalendarDay_container,
isOutsideDay && styles.CalendarDay__outside,
modifiers.has('highlighted-calendar') && styles.CalendarDay__highlighted_calendar,
modifiers.has('blocked-minimum-nights') && styles.CalendarDay__blocked_minimum_nights,
modifiers.has('blocked-calendar') && styles.CalendarDay__blocked_calendar,
modifiers.has('highlighted-calendar') &&
styles.CalendarDay__highlighted_calendar,
modifiers.has('blocked-minimum-nights') &&
styles.CalendarDay__blocked_minimum_nights,
modifiers.has('blocked-calendar') &&
styles.CalendarDay__blocked_calendar,
hoveredSpan && styles.CalendarDay__hovered_span,
modifiers.has('selected-span') && styles.CalendarDay__selected_span,
modifiers.has('last-in-range') && styles.CalendarDay__last_in_range,
Expand All @@ -157,10 +156,18 @@ class CalendarDay extends React.Component {
type="button"
ref={this.setButtonRef}
aria-label={ariaLabel}
onMouseEnter={(e) => { this.onDayMouseEnter(day, e); }}
onMouseLeave={(e) => { this.onDayMouseLeave(day, e); }}
onMouseUp={(e) => { e.currentTarget.blur(); }}
onClick={(e) => { this.onDayClick(day, e); }}
onMouseEnter={e => {
this.onDayMouseEnter(day, e);
}}
onMouseLeave={e => {
this.onDayMouseLeave(day, e);
}}
onMouseUp={e => {
e.currentTarget.blur();
}}
onClick={e => {
this.onDayClick(day, e);
}}
tabIndex={tabIndex}
>
{renderDay ? renderDay(day) : day.format('D')}
Expand Down Expand Up @@ -348,5 +355,4 @@ export default withStyles(({ reactDates: { color } }) => ({

CalendarDay__selected_start: {},
CalendarDay__selected_end: {},

}))(CalendarDay);
42 changes: 27 additions & 15 deletions src/components/CalendarMonth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class CalendarMonth extends React.Component {
weeks: getCalendarMonthWeeks(
props.month,
props.enableOutsideDays,
props.firstDayOfWeek == null ? moment.localeData().firstDayOfWeek() : props.firstDayOfWeek,
props.firstDayOfWeek == null
? moment.localeData().firstDayOfWeek()
: props.firstDayOfWeek,
),
};

Expand All @@ -98,14 +100,18 @@ class CalendarMonth extends React.Component {

componentWillReceiveProps(nextProps) {
const { month, enableOutsideDays, firstDayOfWeek } = nextProps;
if (!month.isSame(this.props.month)
|| enableOutsideDays !== this.props.enableOutsideDays
|| firstDayOfWeek !== this.props.firstDayOfWeek) {
if (
!month.isSame(this.props.month) ||
enableOutsideDays !== this.props.enableOutsideDays ||
firstDayOfWeek !== this.props.firstDayOfWeek
) {
this.setState({
weeks: getCalendarMonthWeeks(
month,
enableOutsideDays,
firstDayOfWeek == null ? moment.localeData().firstDayOfWeek() : firstDayOfWeek,
firstDayOfWeek == null
? moment.localeData().firstDayOfWeek()
: firstDayOfWeek,
),
});
}
Expand All @@ -123,7 +129,12 @@ class CalendarMonth extends React.Component {

setMonthHeight() {
const { setMonthHeight } = this.props;
const captionHeight = calculateDimension(this.captionRef, 'height', true, true);
const captionHeight = calculateDimension(
this.captionRef,
'height',
true,
true,
);
const gridHeight = calculateDimension(this.gridRef, 'height');

setMonthHeight(captionHeight + gridHeight + 1);
Expand Down Expand Up @@ -157,16 +168,20 @@ class CalendarMonth extends React.Component {
} = this.props;

const { weeks } = this.state;
const monthTitle = renderMonth ? renderMonth(month) : month.format(monthFormat);
const monthTitle = renderMonth
? renderMonth(month)
: month.format(monthFormat);

const verticalScrollable = orientation === VERTICAL_SCROLLABLE;

return (
<div
{...css(
styles.CalendarMonth,
orientation === HORIZONTAL_ORIENTATION && styles.CalendarMonth__horizontal,
orientation === VERTICAL_ORIENTATION && styles.CalendarMonth__vertical,
orientation === HORIZONTAL_ORIENTATION &&
styles.CalendarMonth__horizontal,
orientation === VERTICAL_ORIENTATION &&
styles.CalendarMonth__vertical,
verticalScrollable && styles.CalendarMonth__verticalScrollable,
)}
data-visible={isVisible}
Expand All @@ -175,16 +190,14 @@ class CalendarMonth extends React.Component {
ref={this.setCaptionRef}
{...css(
styles.CalendarMonth_caption,
verticalScrollable && styles.CalendarMonth_caption__verticalScrollable,
verticalScrollable &&
styles.CalendarMonth_caption__verticalScrollable,
)}
>
<strong>{monthTitle}</strong>
</div>

<table
{...css(styles.CalendarMonth_table)}
role="presentation"
>
<table {...css(styles.CalendarMonth_table)} role="presentation">
<tbody ref={this.setGridRef}>
{weeks.map((week, i) => (
<tr key={i}>
Expand Down Expand Up @@ -244,4 +257,3 @@ export default withStyles(({ reactDates: { color, font, spacing } }) => ({
paddingBottom: 7,
},
}))(CalendarMonth);

Loading