Skip to content

Commit d99dbaa

Browse files
committed
chore: add prettier and format code
1 parent e7f076e commit d99dbaa

9 files changed

+185
-138
lines changed

.eslintrc

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
22
"parser": "babel-eslint",
3-
"extends": [
4-
"eslint-config-airbnb",
5-
],
3+
"extends": ["eslint-config-airbnb", "prettier", "prettier/react"],
64
"rules": {
7-
"indent": [2, 2, {"SwitchCase": 1}],
5+
"indent": [2, 2, { "SwitchCase": 1 }],
86
"no-console": [0],
97
"func-names": [0],
108
"semi": [2, "never"],
119
"no-extra-semi": [2],
12-
"space-before-function-paren": [2, "always"],
1310
"no-else-return": [0],
1411
"space-infix-ops": [0],
1512
"react/prefer-es6-class": [0],
@@ -18,10 +15,10 @@
1815
"react/no-unused-prop-types": [0],
1916
"react/jsx-filename-extension": [0],
2017
"react/no-string-refs": [0],
21-
"import/extensions": [0],
18+
"import/extensions": [0]
2219
},
2320
"env": {
2421
"browser": true,
25-
"node": true,
26-
},
22+
"node": true
23+
}
2724
}

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"arrowParens": "avoid",
3+
"semi": false,
4+
"singleQuote": true
5+
}

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
"eslint": "^3.8.0",
2525
"eslint-config-airbnb": "^12.0.0",
2626
"eslint-config-airbnb-base": "^9.0.0",
27+
"eslint-config-prettier": "^6.13.0",
2728
"eslint-plugin-import": "^2.0.1",
2829
"eslint-plugin-jsx-a11y": "^2.2.3",
2930
"eslint-plugin-react": "^6.4.1",
3031
"mocha": "^3.1.2",
3132
"mocha-unfunk-reporter": "^0.4.0",
32-
"pre-commit": "^1.0.5"
33+
"pre-commit": "^1.0.5",
34+
"prettier": "2.1.2"
3335
},
3436
"directories": {
3537
"example": "examples"
@@ -57,6 +59,7 @@
5759
"watch": "./node_modules/.bin/webpack-dev-server --hot",
5860
"publish-patch": "npm run build && npm version patch && npm publish; git push; git push --tags",
5961
"lint": "eslint --ignore-path .gitignore src/*",
60-
"lint:fix": "eslint --ignore-path .gitignore . --fix"
62+
"lint:fix": "eslint --ignore-path .gitignore . --fix",
63+
"format": "prettier --config .prettierrc --write 'src/**/*.{js,jsx}'"
6164
}
6265
}

src/index.js

+34-31
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class Headroom extends Component {
2424
style: PropTypes.object,
2525
calcHeightOnResize: PropTypes.bool,
2626
tag: PropTypes.string,
27-
};
27+
}
2828

2929
static defaultProps = {
3030
parent: () => window,
@@ -39,9 +39,9 @@ export default class Headroom extends Component {
3939
pinStart: 0,
4040
calcHeightOnResize: true,
4141
tag: 'div',
42-
};
42+
}
4343

44-
static getDerivedStateFromProps (props, state) {
44+
static getDerivedStateFromProps(props, state) {
4545
if (props.disable && state.state !== 'unfixed') {
4646
return {
4747
translateY: 0,
@@ -54,7 +54,7 @@ export default class Headroom extends Component {
5454
return null
5555
}
5656

57-
constructor (props) {
57+
constructor(props) {
5858
super(props)
5959
// Class variables.
6060
this.currentScrollY = 0
@@ -69,7 +69,7 @@ export default class Headroom extends Component {
6969
}
7070
}
7171

72-
componentDidMount () {
72+
componentDidMount() {
7373
this.setHeightOffset()
7474

7575
this.eventListenerOptions = supportsPassiveEvents()
@@ -97,14 +97,14 @@ export default class Headroom extends Component {
9797
}
9898
}
9999

100-
shouldComponentUpdate (nextProps, nextState) {
100+
shouldComponentUpdate(nextProps, nextState) {
101101
return (
102102
!shallowequal(this.props, nextProps) ||
103103
!shallowequal(this.state, nextState)
104104
)
105105
}
106106

107-
componentDidUpdate (prevProps, prevState) {
107+
componentDidUpdate(prevProps, prevState) {
108108
// If children have changed, remeasure height.
109109
if (prevProps.children !== this.props.children) {
110110
this.setHeightOffset()
@@ -151,7 +151,7 @@ export default class Headroom extends Component {
151151
}
152152
}
153153

154-
componentWillUnmount () {
154+
componentWillUnmount() {
155155
if (this.props.parent()) {
156156
this.props
157157
.parent()
@@ -190,55 +190,55 @@ export default class Headroom extends Component {
190190
} else if (this.props.parent().scrollTop !== undefined) {
191191
return this.props.parent().scrollTop
192192
} else {
193-
return (document.documentElement || document.body.parentNode || document.body).scrollTop
193+
return (
194+
document.documentElement ||
195+
document.body.parentNode ||
196+
document.body
197+
).scrollTop
194198
}
195199
}
196200

197-
getViewportHeight = () => (
198-
window.innerHeight
199-
|| document.documentElement.clientHeight
200-
|| document.body.clientHeight
201-
)
201+
getViewportHeight = () =>
202+
window.innerHeight ||
203+
document.documentElement.clientHeight ||
204+
document.body.clientHeight
202205

203206
getDocumentHeight = () => {
204207
const body = document.body
205208
const documentElement = document.documentElement
206209

207210
return Math.max(
208-
body.scrollHeight, documentElement.scrollHeight,
209-
body.offsetHeight, documentElement.offsetHeight,
210-
body.clientHeight, documentElement.clientHeight
211+
body.scrollHeight,
212+
documentElement.scrollHeight,
213+
body.offsetHeight,
214+
documentElement.offsetHeight,
215+
body.clientHeight,
216+
documentElement.clientHeight
211217
)
212218
}
213219

214-
getElementPhysicalHeight = elm => Math.max(
215-
elm.offsetHeight,
216-
elm.clientHeight
217-
)
220+
getElementPhysicalHeight = elm => Math.max(elm.offsetHeight, elm.clientHeight)
218221

219-
getElementHeight = elm => Math.max(
220-
elm.scrollHeight,
221-
elm.offsetHeight,
222-
elm.clientHeight,
223-
)
222+
getElementHeight = elm =>
223+
Math.max(elm.scrollHeight, elm.offsetHeight, elm.clientHeight)
224224

225225
getScrollerPhysicalHeight = () => {
226226
const parent = this.props.parent()
227227

228-
return (parent === window || parent === document.body)
228+
return parent === window || parent === document.body
229229
? this.getViewportHeight()
230230
: this.getElementPhysicalHeight(parent)
231231
}
232232

233233
getScrollerHeight = () => {
234234
const parent = this.props.parent()
235235

236-
return (parent === window || parent === document.body)
236+
return parent === window || parent === document.body
237237
? this.getDocumentHeight()
238238
: this.getElementHeight(parent)
239239
}
240240

241-
isOutOfBound = (currentScrollY) => {
241+
isOutOfBound = currentScrollY => {
242242
const pastTop = currentScrollY < 0
243243

244244
const scrollerPhysicalHeight = this.getScrollerPhysicalHeight()
@@ -333,7 +333,7 @@ export default class Headroom extends Component {
333333
this.scrollTicking = false
334334
}
335335

336-
render () {
336+
render() {
337337
const { className: userClassName, tag: Tag, ...divProps } = this.props
338338
delete divProps.onUnpin
339339
delete divProps.onPin
@@ -350,7 +350,10 @@ export default class Headroom extends Component {
350350
const { style, wrapperStyle, ...rest } = divProps
351351

352352
let innerStyle = {
353-
position: this.props.disable || this.state.state === 'unfixed' ? 'relative' : 'fixed',
353+
position:
354+
this.props.disable || this.state.state === 'unfixed'
355+
? 'relative'
356+
: 'fixed',
354357
top: 0,
355358
left: 0,
356359
right: 0,

src/shouldUpdate.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function (
2121
scrollDirection,
2222
distanceScrolled,
2323
}
24-
// We're unfixed and headed down. Carry on.
24+
// We're unfixed and headed down. Carry on.
2525
} else if (
2626
currentScrollY <= state.height &&
2727
scrollDirection === 'down' &&
@@ -33,7 +33,7 @@ export default function (
3333
distanceScrolled,
3434
}
3535
} else if (
36-
currentScrollY > (state.height + props.pinStart) &&
36+
currentScrollY > state.height + props.pinStart &&
3737
scrollDirection === 'down' &&
3838
state.state === 'unfixed'
3939
) {
@@ -42,19 +42,20 @@ export default function (
4242
scrollDirection,
4343
distanceScrolled,
4444
}
45-
// We're past the header and scrolling down.
46-
// We transition to "unpinned" if necessary.
45+
// We're past the header and scrolling down.
46+
// We transition to "unpinned" if necessary.
4747
} else if (
4848
scrollDirection === 'down' &&
4949
['pinned', 'unfixed'].indexOf(state.state) >= 0 &&
50-
currentScrollY > (state.height + props.pinStart) && distanceScrolled > props.downTolerance
50+
currentScrollY > state.height + props.pinStart &&
51+
distanceScrolled > props.downTolerance
5152
) {
5253
return {
5354
action: 'unpin',
5455
scrollDirection,
5556
distanceScrolled,
5657
}
57-
// We're scrolling up, we transition to "pinned"
58+
// We're scrolling up, we transition to "pinned"
5859
} else if (
5960
scrollDirection === 'up' &&
6061
distanceScrolled > props.upTolerance &&
@@ -65,8 +66,8 @@ export default function (
6566
scrollDirection,
6667
distanceScrolled,
6768
}
68-
// We're scrolling up, and inside the header.
69-
// We transition to pin regardless of upTolerance
69+
// We're scrolling up, and inside the header.
70+
// We transition to pin regardless of upTolerance
7071
} else if (
7172
scrollDirection === 'up' &&
7273
currentScrollY <= state.height &&

src/supportsPassiveEvents.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners
44
* @returns Boolean
55
*/
6-
export default function supportsPassiveEvents () {
6+
export default function supportsPassiveEvents() {
77
let passiveSupported = false
88

99
try {
1010
const options = {
11-
get passive () {
11+
get passive() {
1212
// This function will be called when the browser
1313
// attempts to access the passive property.
1414
passiveSupported = true

test/.eslintrc

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"extends" : "../.eslintrc",
3-
"env" : {
4-
"mocha" : true
2+
"extends": "../.eslintrc",
3+
"env": {
4+
"mocha": true
55
},
6-
"globals" : {
7-
"describe": true,
6+
"globals": {
7+
"describe": true
88
}
99
}

0 commit comments

Comments
 (0)