Skip to content

Commit 96a6e15

Browse files
Merge pull request #22 from markusguenther/migrate-to-prettier
Migrate to prettier
2 parents c00a2ae + 3e0245c commit 96a6e15

File tree

8 files changed

+744
-522
lines changed

8 files changed

+744
-522
lines changed

.eslintrc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
{
2-
"extends": "eslint-config-rackt",
2+
"extends": "prettier",
33
"env": {
44
"browser": true,
55
"mocha": true,
66
"node": true
77
},
8+
"parser": "babel-eslint",
9+
"parserOptions": {
10+
"ecmaVersion": 6,
11+
"sourceType": "module",
12+
"ecmaFeatures": {
13+
"jsx": true,
14+
"modules": true,
15+
"experimentalObjectRestSpread": true
16+
}
17+
},
818
"rules": {
19+
"prettier/prettier": "warn",
920
"valid-jsdoc": 2,
1021
"react/jsx-uses-vars": 1,
1122
"react/jsx-uses-react": 1,
1223
"react/jsx-no-undef": 2
1324
},
14-
"plugins": [
15-
"react"
16-
]
25+
"plugins": ["prettier", "react"]
1726
}

.prettierrc

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

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@
2828
"@types/react": "^16.4.7",
2929
"babel-cli": "^6.26.0",
3030
"babel-core": "^6.26.3",
31-
"babel-eslint": "^7.2.3",
31+
"babel-eslint": "^8.2.6",
3232
"babel-plugin-transform-decorators-legacy": "^1.3.5",
3333
"babel-preset-es2015": "^6.24.1",
3434
"babel-preset-react": "^6.24.1",
3535
"babel-preset-stage-0": "^6.24.1",
36-
"eslint": "^3.19.0",
37-
"eslint-config-rackt": "^1.1.1",
38-
"eslint-plugin-babel": "^4.1.1",
36+
"eslint": "^5.3.0",
37+
"eslint-config-prettier": "^2.9.0",
38+
"eslint-plugin-prettier": "^2.6.2",
3939
"eslint-plugin-react": "^7.10.0",
4040
"expect": "^1.18.0",
4141
"fbjs": "^0.8.17",
4242
"jsdom": "^9.8.3",
4343
"mocha": "^3.3.0",
44+
"prettier": "^1.14.0",
4445
"prop-types": "^15.6.2",
4546
"react": "^16.4.2",
4647
"react-dom": "^16.4.2",
@@ -55,6 +56,7 @@
5556
"scripts": {
5657
"build": "babel src --out-dir lib",
5758
"lint": "eslint src test",
59+
"lint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
5860
"prepublish": "rimraf lib && npm run build",
5961
"test": "mocha --compilers js:babel-core/register --recursive --reporter spec --require ./test/setup.js",
6062
"test:watch": "npm test -- --watch"
@@ -73,9 +75,7 @@
7375
"expect",
7476
"mocha",
7577
"sinon",
76-
"jsdom",
77-
"eslint",
78-
"babel-eslint"
78+
"jsdom"
7979
]
8080
}
8181
}

src/components/themr.js

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ const DEFAULT_OPTIONS = {
2121
mapThemrProps: defaultMapThemrProps
2222
}
2323

24-
const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
25-
Symbol('THEMR_CONFIG') :
26-
'__REACT_CSS_THEMR_CONFIG__'
24+
const THEMR_CONFIG =
25+
typeof Symbol !== 'undefined'
26+
? Symbol('THEMR_CONFIG')
27+
: '__REACT_CSS_THEMR_CONFIG__'
2728

2829
/**
2930
* Themr decorator
@@ -32,7 +33,7 @@ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
3233
* @param {{}} [options] - Themr options
3334
* @returns {function(ThemedComponent:Function):Function} - ThemedComponent
3435
*/
35-
export default (componentName, localTheme, options = {}) => (ThemedComponent) => {
36+
export default (componentName, localTheme, options = {}) => ThemedComponent => {
3637
const {
3738
composeTheme: optionComposeTheme,
3839
mapThemrProps: optionMapThemrProps
@@ -54,15 +55,21 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
5455
* @property {{wrappedInstance: *}} refs
5556
*/
5657
class Themed extends Component {
57-
static displayName = `Themed${(ThemedComponent.displayName || ThemedComponent.name || "Component")}`;
58+
static displayName = `Themed${ThemedComponent.displayName ||
59+
ThemedComponent.name ||
60+
'Component'}`
5861

5962
static contextTypes = {
6063
themr: PropTypes.object
6164
}
6265

6366
static propTypes = {
6467
...ThemedComponent.propTypes,
65-
composeTheme: PropTypes.oneOf([ COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE ]),
68+
composeTheme: PropTypes.oneOf([
69+
COMPOSE_DEEPLY,
70+
COMPOSE_SOFTLY,
71+
DONT_COMPOSE
72+
]),
6673
innerRef: PropTypes.func,
6774
theme: PropTypes.object,
6875
themeNamespace: PropTypes.string,
@@ -81,9 +88,10 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
8188
}
8289

8390
getWrappedInstance() {
84-
invariant(true,
91+
invariant(
92+
true,
8593
'DEPRECATED: To access the wrapped instance, you have to pass ' +
86-
'{ innerRef: fn } and retrieve with a callback ref style.'
94+
'{ innerRef: fn } and retrieve with a callback ref style.'
8795
)
8896

8997
return this.refs.wrappedInstance
@@ -94,13 +102,21 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
94102
if (!themeNamespace) return theme
95103

96104
if (themeNamespace && !theme) {
97-
throw new Error('Invalid themeNamespace use in friendsofreactjs/react-css-themr. ' +
98-
'themeNamespace prop should be used only with theme prop.')
105+
throw new Error(
106+
'Invalid themeNamespace use in friendsofreactjs/react-css-themr. ' +
107+
'themeNamespace prop should be used only with theme prop.'
108+
)
99109
}
100110

101111
return Object.keys(theme)
102112
.filter(key => key.startsWith(themeNamespace))
103-
.reduce((result, key) => ({ ...result, [removeNamespace(key, themeNamespace)]: theme[key] }), {})
113+
.reduce(
114+
(result, key) => ({
115+
...result,
116+
[removeNamespace(key, themeNamespace)]: theme[key]
117+
}),
118+
{}
119+
)
104120
}
105121

106122
getThemeNotComposed(props) {
@@ -118,14 +134,14 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
118134
getTheme(props) {
119135
return props.composeTheme === COMPOSE_SOFTLY
120136
? {
121-
...this.getContextTheme(),
122-
...config.localTheme,
123-
...this.getNamespacedTheme(props)
124-
}
137+
...this.getContextTheme(),
138+
...config.localTheme,
139+
...this.getNamespacedTheme(props)
140+
}
125141
: themeable(
126-
themeable(this.getContextTheme(), config.localTheme),
127-
this.getNamespacedTheme(props)
128-
)
142+
themeable(this.getContextTheme(), config.localTheme),
143+
this.getNamespacedTheme(props)
144+
)
129145
}
130146

131147
calcTheme(props) {
@@ -208,7 +224,9 @@ function merge(original = {}, mixin = {}) {
208224

209225
default: {
210226
//can't merge an object with a non-object
211-
throw new Error(`You are merging object ${key} with a non-object ${originalValue}`)
227+
throw new Error(
228+
`You are merging object ${key} with a non-object ${originalValue}`
229+
)
212230
}
213231
}
214232
break
@@ -225,7 +243,9 @@ function merge(original = {}, mixin = {}) {
225243
switch (typeof originalValue) {
226244
case 'object': {
227245
//can't merge a non-object with an object
228-
throw new Error(`You are merging non-object ${mixinValue} with an object ${key}, (can occur when using empty or :global only base theme stylesheet)`)
246+
throw new Error(
247+
`You are merging non-object ${mixinValue} with an object ${key}, (can occur when using empty or :global only base theme stylesheet)`
248+
)
229249
}
230250

231251
case 'undefined': {
@@ -240,9 +260,12 @@ function merge(original = {}, mixin = {}) {
240260

241261
default: {
242262
//finally we can merge
243-
result[key] = originalValue.split(' ')
263+
result[key] = originalValue
264+
.split(' ')
244265
.concat(mixinValue.split(' '))
245-
.filter((item, pos, self) => self.indexOf(item) === pos && item !== '')
266+
.filter(
267+
(item, pos, self) => self.indexOf(item) === pos && item !== ''
268+
)
246269
.join(' ')
247270
break
248271
}
@@ -263,7 +286,9 @@ function merge(original = {}, mixin = {}) {
263286
* @returns {undefined}
264287
*/
265288
function validateComposeOption(composeTheme) {
266-
if ([ COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE ].indexOf(composeTheme) === -1) {
289+
if (
290+
[COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE].indexOf(composeTheme) === -1
291+
) {
267292
throw new Error(
268293
`Invalid composeTheme option for friendsofreactjs/react-css-themr. Valid composition options\
269294
are ${COMPOSE_DEEPLY}, ${COMPOSE_SOFTLY} and ${DONT_COMPOSE}. The given\
@@ -294,10 +319,10 @@ function removeNamespace(key, themeNamespace) {
294319
*/
295320
function defaultMapThemrProps(ownProps, theme) {
296321
const {
297-
composeTheme, //eslint-disable-line no-unused-vars
322+
composeTheme, //eslint-disable-line no-unused-vars
298323
innerRef,
299324
themeNamespace, //eslint-disable-line no-unused-vars
300-
mapThemrProps, //eslint-disable-line no-unused-vars
325+
mapThemrProps, //eslint-disable-line no-unused-vars
301326
...rest
302327
} = ownProps
303328

test/components/ThemeProvider.spec.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import PropTypes from 'prop-types'
44
import TestUtils from 'react-dom/test-utils'
55
import { ThemeProvider } from '../../src/index'
66

7-
8-
before(function () {
7+
before(function() {
98
/* eslint-disable no-console */
10-
console.error = function () {}
9+
console.error = function() {}
1110
})
1211

13-
after(function () {
12+
after(function() {
1413
delete console.error
1514
})
1615

@@ -33,23 +32,26 @@ describe('ThemeProvider', () => {
3332
ThemeProvider.propTypes = {}
3433

3534
try {
36-
expect(() => TestUtils.renderIntoDocument(
37-
<ThemeProvider theme={theme}>
38-
<div />
39-
</ThemeProvider>
40-
)).toNotThrow()
35+
expect(() =>
36+
TestUtils.renderIntoDocument(
37+
<ThemeProvider theme={theme}>
38+
<div />
39+
</ThemeProvider>
40+
)
41+
).toNotThrow()
4142

42-
expect(() => TestUtils.renderIntoDocument(
43-
<ThemeProvider theme={theme}>
44-
<div />
45-
<div />
46-
</ThemeProvider>
47-
)).toThrow(/expected to receive a single React element child/)
43+
expect(() =>
44+
TestUtils.renderIntoDocument(
45+
<ThemeProvider theme={theme}>
46+
<div />
47+
<div />
48+
</ThemeProvider>
49+
)
50+
).toThrow(/expected to receive a single React element child/)
4851

49-
expect(() => TestUtils.renderIntoDocument(
50-
<ThemeProvider theme={theme}>
51-
</ThemeProvider>
52-
)).toThrow(/expected to receive a single React element child/)
52+
expect(() =>
53+
TestUtils.renderIntoDocument(<ThemeProvider theme={theme} />)
54+
).toThrow(/expected to receive a single React element child/)
5355
} finally {
5456
ThemeProvider.propTypes = propTypes
5557
}

0 commit comments

Comments
 (0)