Skip to content

Commit 976f2b2

Browse files
committed
Update linting
1 parent 209d0f2 commit 976f2b2

File tree

6 files changed

+109
-89
lines changed

6 files changed

+109
-89
lines changed

.eslintrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "eslint-config-rackt",
3+
"env": {
4+
"browser": true,
5+
"mocha": true,
6+
"node": true
7+
},
8+
"rules": {
9+
"valid-jsdoc": 2,
10+
"react/jsx-uses-vars": 1,
11+
"react/jsx-uses-react": 1,
12+
"react/jsx-no-undef": 2,
13+
"react/wrap-multilines": 2
14+
},
15+
"plugins": [
16+
"react"
17+
]
18+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"build": "babel src --out-dir lib",
1212
"prepublish": "rimraf lib && npm run build",
13+
"lint": "eslint src test",
1314
"test": "mocha --compilers js:babel-core/register --recursive --reporter spec --require ./test/setup.js",
1415
"test:watch": "npm test -- --watch"
1516
},
@@ -24,6 +25,7 @@
2425
"babel-preset-react": "^6.5.0",
2526
"babel-preset-stage-0": "^6.5.0",
2627
"eslint": "^2.8.0",
28+
"eslint-config-rackt": "^1.1.1",
2729
"eslint-plugin-babel": "^3.2.0",
2830
"eslint-plugin-react": "^5.0.1",
2931
"expect": "^1.18.0",

src/components/ThemeProvider.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { Children, Component, PropTypes } from 'react';
2-
import themrShape from '../utils/themr-shape';
1+
import { Children, Component, PropTypes } from 'react'
2+
import themrShape from '../utils/themr-shape'
33

44
export default class ThemeProvider extends Component {
55
static propTypes = {
66
children: PropTypes.element.isRequired,
77
theme: PropTypes.object.isRequired
8-
};
8+
}
99

1010
static defaultProps = {
1111
theme: {}
12-
};
12+
}
1313

1414
static childContextTypes = {
1515
themr: themrShape.isRequired
16-
};
16+
}
1717

18-
getChildContext () {
18+
getChildContext() {
1919
return {
2020
themr: {
2121
theme: this.props.theme
2222
}
23-
};
23+
}
2424
}
2525

26-
render () {
27-
return Children.only(this.props.children);
26+
render() {
27+
return Children.only(this.props.children)
2828
}
2929
}

src/components/themr.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import React, { Component, PropTypes } from 'react';
1+
import React, { Component, PropTypes } from 'react'
22

3-
const COMPOSE_DEEPLY = 'deeply';
4-
const COMPOSE_SOFTLY = 'softly';
5-
const DONT_COMPOSE = false;
3+
const COMPOSE_DEEPLY = 'deeply'
4+
const COMPOSE_SOFTLY = 'softly'
5+
const DONT_COMPOSE = false
66

77
const DEFAULT_OPTIONS = {
88
composeTheme: COMPOSE_DEEPLY
9-
};
9+
}
1010

1111
export default (componentName, localTheme, options = DEFAULT_OPTIONS) => (ThemedComponent) => {
12-
const { composeTheme: optionComposeTheme } = options;
13-
validateComposeOption(optionComposeTheme);
12+
const { composeTheme: optionComposeTheme } = options
13+
validateComposeOption(optionComposeTheme)
1414
return class Themed extends Component {
1515
static contextTypes = {
1616
themr: PropTypes.object
17-
};
17+
}
1818

1919
static propTypes = {
2020
composeTheme: PropTypes.oneOf([ COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE ]),
2121
theme: PropTypes.object
22-
};
22+
}
2323

2424
static defaultProps = {
2525
composeTheme: optionComposeTheme
26-
};
26+
}
2727

2828
getThemeNotComposed() {
29-
if (this.props.theme) return this.props.theme;
30-
if (localTheme) return localTheme;
31-
return contextTheme;
29+
if (this.props.theme) return this.props.theme
30+
if (localTheme) return localTheme
31+
return this.getContextTheme()
3232
}
3333

3434
getContextTheme() {
@@ -40,35 +40,35 @@ export default (componentName, localTheme, options = DEFAULT_OPTIONS) => (Themed
4040
getTheme() {
4141
return this.props.composeTheme === COMPOSE_SOFTLY
4242
? Object.assign({}, this.getContextTheme(), localTheme, this.props.theme)
43-
: themeable(themeable(this.getContextTheme(), localTheme), this.props.theme);
43+
: themeable(themeable(this.getContextTheme(), localTheme), this.props.theme)
4444
}
4545

46-
render () {
46+
render() {
4747
return React.createElement(ThemedComponent, {
4848
...this.props,
4949
theme: this.props.composeTheme
5050
? this.getTheme()
5151
: this.getThemeNotComposed()
52-
});
52+
})
5353
}
5454
}
55-
};
55+
}
5656

5757
function themeable(style = {}, theme) {
58-
if (!theme) return style;
59-
return [...Object.keys(theme), ...Object.keys(style)].reduce((result, key) => (
58+
if (!theme) return style
59+
return [ ...Object.keys(theme), ...Object.keys(style) ].reduce((result, key) => (
6060
theme[key] && style[key] && theme[key].indexOf(style[key]) === -1
6161
? { ...result, [key]: `${style[key]} ${theme[key]}` }
6262
: { ...result, [key]: theme[key] || style[key] }
63-
), {});
63+
), {})
6464
}
6565

6666
function validateComposeOption(composeTheme) {
67-
if ([COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE].indexOf(composeTheme) === -1) {
67+
if ([ COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE ].indexOf(composeTheme) === -1) {
6868
throw new Error(
6969
`Invalid composeTheme option for react-css-themr. Valid composition options\
7070
are ${COMPOSE_DEEPLY}, ${COMPOSE_SOFTLY} and ${DONT_COMPOSE}. The given\
7171
option was ${composeTheme}`
72-
);
72+
)
7373
}
7474
}

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default as ThemeProvider } from './components/ThemeProvider';
2-
export { default as themr } from './components/themr';
1+
export { default as ThemeProvider } from './components/ThemeProvider'
2+
export { default as themr } from './components/themr'

test/components/themr.spec.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Themr decorator function', () => {
2525
}
2626

2727
it('passes a context theme object using the component\'s context', () => {
28-
const theme = { Container: { foo: 'foo_1234' } };
28+
const theme = { Container: { foo: 'foo_1234' } }
2929

3030
@themr('Container')
3131
class Container extends Component {
@@ -45,8 +45,8 @@ describe('Themr decorator function', () => {
4545
})
4646

4747
it('passes a context theme object using the component\'s theme prop', () => {
48-
const containerTheme = { foo: 'foo_1234' };
49-
const theme = { Container: containerTheme };
48+
const containerTheme = { foo: 'foo_1234' }
49+
const theme = { Container: containerTheme }
5050

5151
@themr('Container')
5252
class Container extends Component {
@@ -62,14 +62,14 @@ describe('Themr decorator function', () => {
6262
)
6363

6464
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
65-
expect(stub.props.theme).toEqual(containerTheme);
65+
expect(stub.props.theme).toEqual(containerTheme)
6666
})
6767

6868
it('passes a theme composed from context, local and props', () => {
69-
const containerTheme = { foo: 'foo_123' };
70-
const containerThemeLocal = { foo: 'foo_567' };
71-
const containerThemeProps = { foo: 'foo_89' };
72-
const theme = { Container: containerTheme };
69+
const containerTheme = { foo: 'foo_123' }
70+
const containerThemeLocal = { foo: 'foo_567' }
71+
const containerThemeProps = { foo: 'foo_89' }
72+
const theme = { Container: containerTheme }
7373

7474
@themr('Container', containerThemeLocal)
7575
class Container extends Component {
@@ -84,15 +84,15 @@ describe('Themr decorator function', () => {
8484
</ProviderMock>
8585
)
8686

87-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
88-
const expectedTheme = { foo: 'foo_123 foo_567 foo_89' };
89-
expect(stub.props.theme).toEqual(expectedTheme);
87+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
88+
const expectedTheme = { foo: 'foo_123 foo_567 foo_89' }
89+
expect(stub.props.theme).toEqual(expectedTheme)
9090
})
9191

9292
it('passes a default theme when composition is disabled and with no props', () => {
93-
const containerTheme = { foo: 'foo_123' };
94-
const containerThemeLocal = { foo: 'foo_567' };
95-
const theme = { Container: containerTheme };
93+
const containerTheme = { foo: 'foo_123' }
94+
const containerThemeLocal = { foo: 'foo_567' }
95+
const theme = { Container: containerTheme }
9696

9797
@themr('Container', containerThemeLocal, { composeTheme: false })
9898
class Container extends Component {
@@ -107,14 +107,14 @@ describe('Themr decorator function', () => {
107107
</ProviderMock>
108108
)
109109

110-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
111-
expect(stub.props.theme).toEqual(containerThemeLocal);
110+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
111+
expect(stub.props.theme).toEqual(containerThemeLocal)
112112
})
113113

114114
it('when providing decorator options composes a theme object deeply', () => {
115-
const containerTheme = { foo: 'foo_123' };
116-
const containerTheme2 = { foo: 'foo_567' };
117-
const theme = { Container: containerTheme };
115+
const containerTheme = { foo: 'foo_123' }
116+
const containerTheme2 = { foo: 'foo_567' }
117+
const theme = { Container: containerTheme }
118118

119119
@themr('Container')
120120
class Container extends Component {
@@ -129,15 +129,15 @@ describe('Themr decorator function', () => {
129129
</ProviderMock>
130130
)
131131

132-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
133-
const expectedTheme = { foo: 'foo_123 foo_567' };
134-
expect(stub.props.theme).toEqual(expectedTheme);
135-
});
132+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
133+
const expectedTheme = { foo: 'foo_123 foo_567' }
134+
expect(stub.props.theme).toEqual(expectedTheme)
135+
})
136136

137137
it('when providing decorator options composes a theme object softly', () => {
138-
const containerTheme = { foo: 'foo_123', bar: 'bar_765' };
139-
const containerTheme2 = { foo: 'foo_567' };
140-
const theme = { Container: containerTheme };
138+
const containerTheme = { foo: 'foo_123', bar: 'bar_765' }
139+
const containerTheme2 = { foo: 'foo_567' }
140+
const theme = { Container: containerTheme }
141141

142142
@themr('Container', null, { composeTheme: 'softly' })
143143
class Container extends Component {
@@ -152,15 +152,15 @@ describe('Themr decorator function', () => {
152152
</ProviderMock>
153153
)
154154

155-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
156-
const expectedTheme = { foo: 'foo_567', bar: 'bar_765' };
157-
expect(stub.props.theme).toEqual(expectedTheme);
158-
});
155+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
156+
const expectedTheme = { foo: 'foo_567', bar: 'bar_765' }
157+
expect(stub.props.theme).toEqual(expectedTheme)
158+
})
159159

160160
it('when providing decorator options does not compose a theme', () => {
161-
const containerTheme = { foo: 'foo_123' };
162-
const containerTheme2 = { foo: 'foo_567' };
163-
const theme = { Container: containerTheme };
161+
const containerTheme = { foo: 'foo_123' }
162+
const containerTheme2 = { foo: 'foo_567' }
163+
const theme = { Container: containerTheme }
164164

165165
@themr('Container', null, { composeTheme: false })
166166
class Container extends Component {
@@ -175,14 +175,14 @@ describe('Themr decorator function', () => {
175175
</ProviderMock>
176176
)
177177

178-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
179-
expect(stub.props.theme).toEqual(containerTheme2);
178+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
179+
expect(stub.props.theme).toEqual(containerTheme2)
180180
})
181181

182182
it('when providing props options composes a theme object deeply', () => {
183-
const containerTheme = { foo: 'foo_123' };
184-
const containerTheme2 = { foo: 'foo_567' };
185-
const theme = { Container: containerTheme };
183+
const containerTheme = { foo: 'foo_123' }
184+
const containerTheme2 = { foo: 'foo_567' }
185+
const theme = { Container: containerTheme }
186186

187187
@themr('Container')
188188
class Container extends Component {
@@ -197,15 +197,15 @@ describe('Themr decorator function', () => {
197197
</ProviderMock>
198198
)
199199

200-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
201-
const expectedTheme = { foo: 'foo_123 foo_567' };
202-
expect(stub.props.theme).toEqual(expectedTheme);
203-
});
200+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
201+
const expectedTheme = { foo: 'foo_123 foo_567' }
202+
expect(stub.props.theme).toEqual(expectedTheme)
203+
})
204204

205205
it('when providing props options composes a theme object softly', () => {
206-
const containerTheme = { foo: 'foo_123', bar: 'bar_765' };
207-
const containerTheme2 = { foo: 'foo_567' };
208-
const theme = { Container: containerTheme };
206+
const containerTheme = { foo: 'foo_123', bar: 'bar_765' }
207+
const containerTheme2 = { foo: 'foo_567' }
208+
const theme = { Container: containerTheme }
209209

210210
@themr('Container')
211211
class Container extends Component {
@@ -220,15 +220,15 @@ describe('Themr decorator function', () => {
220220
</ProviderMock>
221221
)
222222

223-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
224-
const expectedTheme = { foo: 'foo_567', bar: 'bar_765' };
225-
expect(stub.props.theme).toEqual(expectedTheme);
226-
});
223+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
224+
const expectedTheme = { foo: 'foo_567', bar: 'bar_765' }
225+
expect(stub.props.theme).toEqual(expectedTheme)
226+
})
227227

228228
it('when providing props options does not compose a theme', () => {
229-
const containerTheme = { foo: 'foo_123' };
230-
const containerTheme2 = { foo: 'foo_567' };
231-
const theme = { Container: containerTheme };
229+
const containerTheme = { foo: 'foo_123' }
230+
const containerTheme2 = { foo: 'foo_567' }
231+
const theme = { Container: containerTheme }
232232

233233
@themr('Container')
234234
class Container extends Component {
@@ -243,8 +243,8 @@ describe('Themr decorator function', () => {
243243
</ProviderMock>
244244
)
245245

246-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
247-
expect(stub.props.theme).toEqual(containerTheme2);
246+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
247+
expect(stub.props.theme).toEqual(containerTheme2)
248248
})
249249

250250
it('throws an error if an invalid composition option passed', () => {
@@ -270,7 +270,7 @@ describe('Themr decorator function', () => {
270270
<Container />
271271
)
272272

273-
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough);
274-
expect(stub.props.theme).toEqual({});
273+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
274+
expect(stub.props.theme).toEqual({})
275275
})
276276
})

0 commit comments

Comments
 (0)