Skip to content

Commit 97d9d1b

Browse files
committed
Update ESLint, update ESLint config, configure Prettier, format all files using new config
1 parent 53a0cbd commit 97d9d1b

30 files changed

+870
-1161
lines changed

.babelrc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"presets": [
3-
"@babel/env",
4-
"@babel/react"
5-
]
2+
"presets": ["@babel/env", "@babel/react"]
63
}

.eslintrc.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
2-
"extends": "wojtekmaj/react",
3-
"parser": "babel-eslint",
2+
"extends": "wojtekmaj/react-no-automatic-runtime",
43
"overrides": [
54
{
6-
"files": [
7-
"sample/**",
8-
"test/**"
9-
],
5+
"files": ["sample/**", "test/**"],
106
"rules": {
117
"import/no-unresolved": "off"
128
}

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn pretty-quick --staged

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.cache
2+
.yarn
3+
coverage
4+
dist
5+
*.yml

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

.vscode/extensions.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"recommendations": [
3-
"dbaeumer.vscode-eslint",
4-
"eamodio.gitlens"
5-
],
6-
"unwantedRecommendations": [
7-
"dbaeumer.jshint"
8-
]
2+
"recommendations": ["dbaeumer.vscode-eslint", "eamodio.gitlens", "esbenp.prettier-vscode"],
3+
"unwantedRecommendations": ["dbaeumer.jshint"]
94
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true,
24
"search.exclude": {
35
"**/.yarn": true
46
}

README.md

Lines changed: 53 additions & 57 deletions
Large diffs are not rendered by default.

jest.config.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
2-
"collectCoverageFrom": [
3-
"**/src/**.{js,jsx}",
4-
"!**/src/entry.js",
5-
"!**/src/entry.nostyle.js"
6-
],
7-
"setupFiles": [
8-
"<rootDir>/jest.setup.js"
9-
],
2+
"collectCoverageFrom": ["**/src/**.{js,jsx}", "!**/src/entry.js", "!**/src/entry.nostyle.js"],
3+
"setupFiles": ["<rootDir>/jest.setup.js"],
104
"testEnvironment": "jsdom"
115
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"copy-styles": "node ./copy-styles.js",
1313
"jest": "jest",
1414
"lint": "eslint sample/ src/ test/ --ext .jsx,.js",
15+
"postinstall": "husky install",
1516
"prepack": "yarn clean && yarn build",
1617
"test": "yarn lint && yarn jest"
1718
},
@@ -49,12 +50,14 @@
4950
"@babel/preset-env": "^7.15.0",
5051
"@babel/preset-react": "^7.14.0",
5152
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.0",
52-
"babel-eslint": "^10.0.0",
5353
"enzyme": "^3.10.0",
54-
"eslint": "~7.19.0",
55-
"eslint-config-wojtekmaj": "^0.5.0",
54+
"eslint": "^8.5.0",
55+
"eslint-config-wojtekmaj": "^0.6.5",
56+
"husky": "^7.0.0",
5657
"jest": "^27.0.0",
5758
"less": "^4.0.0",
59+
"prettier": "^2.5.0",
60+
"pretty-quick": "^3.1.0",
5861
"react": "^17.0.0",
5962
"react-dom": "^17.0.0",
6063
"rimraf": "^3.0.0"

sample/.babelrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"presets": [
3-
["@babel/preset-env", {
4-
"modules": false
5-
}],
3+
[
4+
"@babel/preset-env",
5+
{
6+
"modules": false
7+
}
8+
],
69
"@babel/react"
710
]
811
}

sample/Sample.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ export default function Sample() {
1717
</header>
1818
<div className="Sample__container">
1919
<main className="Sample__container__content">
20-
<DateTimeRangePicker
21-
onChange={onChange}
22-
value={value}
23-
/>
20+
<DateTimeRangePicker onChange={onChange} value={value} />
2421
</main>
2522
</div>
2623
</div>

sample/Sample.less

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
html,
22
body {
3-
height: 100%;
3+
height: 100%;
44
}
55

66
body {
@@ -9,13 +9,14 @@ body {
99
}
1010

1111
.Sample {
12-
input, button {
12+
input,
13+
button {
1314
font: inherit;
1415
}
1516

1617
header {
1718
background-color: rgb(50, 54, 57);
18-
box-shadow: 0 0 8px rgba(0, 0, 0, .5);
19+
box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
1920
padding: 20px;
2021
color: white;
2122

@@ -48,4 +49,4 @@ body {
4849
align-items: stretch;
4950
}
5051
}
51-
}
52+
}

sample/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en-US">
33
<head>
44
<meta charset="utf-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>react-datetimerange-picker sample page</title>
77
</head>
88
<body>

sample/webpack.config.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,15 @@ module.exports = {
2121
rules: [
2222
{
2323
test: /\.jsx?$/,
24-
use: [
25-
'babel-loader',
26-
],
24+
use: ['babel-loader'],
2725
},
2826
{
2927
test: /\.less$/,
30-
use: [
31-
'style-loader',
32-
'css-loader',
33-
'less-loader',
34-
],
28+
use: ['style-loader', 'css-loader', 'less-loader'],
3529
},
3630
{
3731
test: /\.css$/,
38-
use: [
39-
'style-loader',
40-
'css-loader',
41-
],
32+
use: ['style-loader', 'css-loader'],
4233
},
4334
],
4435
},

src/DateTimeRangePicker.jsx

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ export default class DateTimeRangePicker extends PureComponent {
3939

4040
componentDidUpdate(prevProps, prevState) {
4141
const { isCalendarOpen, isClockOpen } = this.state;
42-
const {
43-
onCalendarClose,
44-
onCalendarOpen,
45-
onClockClose,
46-
onClockOpen,
47-
} = this.props;
42+
const { onCalendarClose, onCalendarOpen, onClockClose, onClockOpen } = this.props;
4843

4944
const isWidgetOpen = isCalendarOpen || isClockOpen;
5045
const prevIsWidgetOpen = prevState.isCalendarOpen || prevState.isClockOpen;
@@ -78,7 +73,7 @@ export default class DateTimeRangePicker extends PureComponent {
7873
if (this.wrapper && !this.wrapper.contains(target)) {
7974
this.closeWidgets();
8075
}
81-
}
76+
};
8277

8378
onDateChange = ([valueFrom, valueTo], closeWidgets = true) => {
8479
const { value } = this.props;
@@ -117,7 +112,7 @@ export default class DateTimeRangePicker extends PureComponent {
117112
})();
118113

119114
this.onChange([nextValueFrom, nextValueTo], closeWidgets);
120-
}
115+
};
121116

122117
// eslint-disable-next-line react/destructuring-assignment
123118
onChange = (value, closeWidgets = this.props.closeWidgets) => {
@@ -130,26 +125,22 @@ export default class DateTimeRangePicker extends PureComponent {
130125
if (onChange) {
131126
onChange(value);
132127
}
133-
}
128+
};
134129

135130
onChangeFrom = (valueFrom, closeWidgets) => {
136131
const { value } = this.props;
137132
const [, valueTo] = [].concat(value);
138133
this.onChange([valueFrom, valueTo], closeWidgets);
139-
}
134+
};
140135

141136
onChangeTo = (valueTo, closeWidgets) => {
142137
const { value } = this.props;
143138
const [valueFrom] = [].concat(value);
144139
this.onChange([valueFrom, valueTo], closeWidgets);
145-
}
140+
};
146141

147142
onFocus = (event) => {
148-
const {
149-
disabled,
150-
onFocus,
151-
openWidgetsOnFocus,
152-
} = this.props;
143+
const { disabled, onFocus, openWidgetsOnFocus } = this.props;
153144

154145
if (onFocus) {
155146
onFocus(event);
@@ -180,34 +171,34 @@ export default class DateTimeRangePicker extends PureComponent {
180171
default:
181172
}
182173
}
183-
}
174+
};
184175

185176
onKeyDown = (event) => {
186177
if (event.key === 'Escape') {
187178
this.closeWidgets();
188179
}
189-
}
180+
};
190181

191182
openClock = () => {
192183
this.setState({
193184
isCalendarOpen: false,
194185
isClockOpen: true,
195186
});
196-
}
187+
};
197188

198189
openCalendar = () => {
199190
this.setState({
200191
isCalendarOpen: true,
201192
isClockOpen: false,
202193
});
203-
}
194+
};
204195

205196
toggleCalendar = () => {
206197
this.setState((prevState) => ({
207198
isCalendarOpen: !prevState.isCalendarOpen,
208199
isClockOpen: false,
209200
}));
210-
}
201+
};
211202

212203
closeWidgets = () => {
213204
this.setState((prevState) => {
@@ -220,7 +211,7 @@ export default class DateTimeRangePicker extends PureComponent {
220211
isClockOpen: false,
221212
};
222213
});
223-
}
214+
};
224215

225216
stopPropagation = (event) => event.stopPropagation();
226217

@@ -230,7 +221,8 @@ export default class DateTimeRangePicker extends PureComponent {
230221
const { isCalendarOpen, isClockOpen } = this.state;
231222
const isWidgetOpen = isCalendarOpen || isClockOpen;
232223

233-
const shouldListenWithFallback = typeof shouldListen !== 'undefined' ? shouldListen : isWidgetOpen;
224+
const shouldListenWithFallback =
225+
typeof shouldListen !== 'undefined' ? shouldListen : isWidgetOpen;
234226
const fnName = shouldListenWithFallback ? 'addEventListener' : 'removeEventListener';
235227
outsideActionEvents.forEach((eventName) => document[fnName](eventName, this.onOutsideAction));
236228
document[fnName]('keydown', this.onKeyDown);
@@ -314,15 +306,14 @@ export default class DateTimeRangePicker extends PureComponent {
314306
<div className={`${baseClassName}__wrapper`}>
315307
<DateTimeInput
316308
{...commonProps}
309+
/* eslint-disable-next-line jsx-a11y/no-autofocus */
317310
autoFocus={autoFocus}
318311
name={`${name}_from`}
319312
onChange={this.onChangeFrom}
320313
returnValue="start"
321314
value={valueFrom}
322315
/>
323-
<span className={`${baseClassName}__range-divider`}>
324-
{rangeDivider}
325-
</span>
316+
<span className={`${baseClassName}__range-divider`}>{rangeDivider}</span>
326317
<DateTimeInput
327318
{...commonProps}
328319
name={`${name}_to`}
@@ -386,7 +377,10 @@ export default class DateTimeRangePicker extends PureComponent {
386377
ref.removeAttribute('style');
387378
}
388379
}}
389-
className={mergeClassNames(className, `${className}--${isCalendarOpen ? 'open' : 'closed'}`)}
380+
className={mergeClassNames(
381+
className,
382+
`${className}--${isCalendarOpen ? 'open' : 'closed'}`,
383+
)}
390384
>
391385
<Calendar
392386
className={calendarClassName}
@@ -519,30 +513,18 @@ DateTimeRangePicker.defaultProps = {
519513
rangeDivider: '–',
520514
};
521515

522-
const isValue = PropTypes.oneOfType([
523-
PropTypes.string,
524-
PropTypes.instanceOf(Date),
525-
]);
516+
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
526517

527518
DateTimeRangePicker.propTypes = {
528519
amPmAriaLabel: PropTypes.string,
529520
autoFocus: PropTypes.bool,
530521
calendarAriaLabel: PropTypes.string,
531-
calendarClassName: PropTypes.oneOfType([
532-
PropTypes.string,
533-
PropTypes.arrayOf(PropTypes.string),
534-
]),
522+
calendarClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
535523
calendarIcon: PropTypes.node,
536-
className: PropTypes.oneOfType([
537-
PropTypes.string,
538-
PropTypes.arrayOf(PropTypes.string),
539-
]),
524+
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
540525
clearAriaLabel: PropTypes.string,
541526
clearIcon: PropTypes.node,
542-
clockClassName: PropTypes.oneOfType([
543-
PropTypes.string,
544-
PropTypes.arrayOf(PropTypes.string),
545-
]),
527+
clockClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
546528
closeWidgets: PropTypes.bool,
547529
dayAriaLabel: PropTypes.string,
548530
dayPlaceholder: PropTypes.string,
@@ -576,10 +558,7 @@ DateTimeRangePicker.propTypes = {
576558
secondAriaLabel: PropTypes.string,
577559
secondPlaceholder: PropTypes.string,
578560
showLeadingZeros: PropTypes.bool,
579-
value: PropTypes.oneOfType([
580-
isValue,
581-
PropTypes.arrayOf(isValue),
582-
]),
561+
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
583562
yearAriaLabel: PropTypes.string,
584563
yearPlaceholder: PropTypes.string,
585564
};

0 commit comments

Comments
 (0)