Skip to content

Commit 7d589dd

Browse files
committed
Fix style + kill unused code
1 parent c3f021a commit 7d589dd

File tree

4 files changed

+66
-75
lines changed

4 files changed

+66
-75
lines changed

__tests__/prefixTree.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ test('it handles a function as the prefix', () => {
3030

3131
const prefixFunc = selector => {
3232
return selector === '.foo' ? 'tw-' : ''
33-
if (selector === '.foo') {
34-
return 'tw-'
35-
}
36-
37-
return ''
3833
}
3934

4035
const result = prefixTree(input, prefixFunc).toResult()

__tests__/processPlugins.test.js

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ function css(nodes) {
77
}
88

99
function processPluginsWithValidConfig(config) {
10-
return processPlugins(_.defaultsDeep(config, {
11-
options: {
12-
prefix: '',
13-
important: false,
14-
separator: ':'
15-
}
16-
}))
10+
return processPlugins(
11+
_.defaultsDeep(config, {
12+
options: {
13+
prefix: '',
14+
important: false,
15+
separator: ':',
16+
},
17+
})
18+
)
1719
}
1820

1921
test('plugins can create utilities with object syntax', () => {
@@ -143,8 +145,8 @@ test('plugins can create utilities with mixed object styles and PostCSS nodes',
143145
addUtilities([
144146
{
145147
'.object-fill': {
146-
objectFit: 'fill'
147-
}
148+
objectFit: 'fill',
149+
},
148150
},
149151
postcss.rule({ selector: '.object-contain' }).append([
150152
postcss.decl({
@@ -182,7 +184,7 @@ test('plugins can create utilities with mixed object styles and PostCSS nodes',
182184
test('plugins can create utilities with variants', () => {
183185
const [components, utilities] = processPluginsWithValidConfig({
184186
plugins: [
185-
function({ rule, addUtilities }) {
187+
function({ addUtilities }) {
186188
addUtilities(
187189
{
188190
'.object-fill': {
@@ -283,6 +285,19 @@ test('plugins can create components with raw PostCSS nodes', () => {
283285
},
284286
],
285287
})
288+
289+
expect(utilities.length).toBe(0)
290+
expect(css(components)).toMatchCss(`
291+
.btn-blue {
292+
background-color: blue;
293+
color: white;
294+
padding: .5rem 1rem;
295+
border-radius: .25rem
296+
}
297+
.btn-blue:hover {
298+
background-color: darkblue
299+
}
300+
`)
286301
})
287302

288303
test('plugins can create components with mixed object styles and raw PostCSS nodes', () => {
@@ -310,8 +325,8 @@ test('plugins can create components with mixed object styles and raw PostCSS nod
310325
]),
311326
{
312327
'.btn-blue:hover': {
313-
backgroundColor: 'darkblue'
314-
}
328+
backgroundColor: 'darkblue',
329+
},
315330
},
316331
])
317332
},
@@ -422,15 +437,15 @@ test('plugins can access the current config', () => {
422437
{
423438
'.container': {
424439
width: '100%',
425-
}
440+
},
426441
},
427442
]
428443

429444
_.forEach(config('screens'), breakpoint => {
430445
containerClasses.push({
431446
[`@media (min-width: ${breakpoint})`]: {
432447
'.container': { maxWidth: breakpoint },
433-
}
448+
},
434449
})
435450
})
436451

@@ -499,7 +514,7 @@ test('plugins can provide fallbacks to keys missing from the config', () => {
499514
test('variants are optional when adding utilities', () => {
500515
const [, utilities] = processPluginsWithValidConfig({
501516
plugins: [
502-
function({ rule, addUtilities }) {
517+
function({ addUtilities }) {
503518
addUtilities({
504519
'.border-collapse': {
505520
'border-collapse': 'collapse',
@@ -578,7 +593,7 @@ test('plugins can add multiple sets of utilities and components', () => {
578593
test('plugins respect prefix and important options by default when adding utilities', () => {
579594
const [, utilities] = processPluginsWithValidConfig({
580595
plugins: [
581-
function({ utility, addUtilities }) {
596+
function({ addUtilities }) {
582597
addUtilities({
583598
'.rotate-90': {
584599
transform: 'rotate(90deg)',
@@ -673,14 +688,17 @@ test("plugins can apply the user's chosen prefix to components manually", () =>
673688
test('prefix can optionally be ignored for utilities', () => {
674689
const [, utilities] = processPluginsWithValidConfig({
675690
plugins: [
676-
function({ utility, addUtilities }) {
677-
addUtilities({
678-
'.rotate-90': {
679-
transform: 'rotate(90deg)',
691+
function({ addUtilities }) {
692+
addUtilities(
693+
{
694+
'.rotate-90': {
695+
transform: 'rotate(90deg)',
696+
},
680697
},
681-
}, {
682-
respectPrefix: false
683-
})
698+
{
699+
respectPrefix: false,
700+
}
701+
)
684702
},
685703
],
686704
options: {
@@ -701,14 +719,17 @@ test('prefix can optionally be ignored for utilities', () => {
701719
test('important can optionally be ignored for utilities', () => {
702720
const [, utilities] = processPluginsWithValidConfig({
703721
plugins: [
704-
function({ utility, addUtilities }) {
705-
addUtilities({
706-
'.rotate-90': {
707-
transform: 'rotate(90deg)',
722+
function({ addUtilities }) {
723+
addUtilities(
724+
{
725+
'.rotate-90': {
726+
transform: 'rotate(90deg)',
727+
},
708728
},
709-
}, {
710-
respectImportant: false
711-
})
729+
{
730+
respectImportant: false,
731+
}
732+
)
712733
},
713734
],
714735
options: {
@@ -729,16 +750,19 @@ test('important can optionally be ignored for utilities', () => {
729750
test('variants can still be specified when ignoring prefix and important options', () => {
730751
const [, utilities] = processPluginsWithValidConfig({
731752
plugins: [
732-
function({ utility, addUtilities }) {
733-
addUtilities({
734-
'.rotate-90': {
735-
transform: 'rotate(90deg)',
753+
function({ addUtilities }) {
754+
addUtilities(
755+
{
756+
'.rotate-90': {
757+
transform: 'rotate(90deg)',
758+
},
736759
},
737-
}, {
738-
variants: ['responsive', 'hover', 'focus'],
739-
respectImportant: false,
740-
respectPrefix: false,
741-
})
760+
{
761+
variants: ['responsive', 'hover', 'focus'],
762+
respectImportant: false,
763+
respectPrefix: false,
764+
}
765+
)
742766
},
743767
],
744768
options: {

src/util/prefixSelector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default function(prefix, selector) {
44
const getPrefix = typeof prefix === 'function' ? prefix : () => prefix
55

66
return parser(selectors => {
7-
selectors.walkClasses((classSelector) => {
7+
selectors.walkClasses(classSelector => {
88
classSelector.value = `${getPrefix('.' + classSelector.value)}${classSelector.value}`
99
})
1010
}).processSync(selector)

src/util/processPlugins.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,12 @@ import parseObjectStyles from '../util/parseObjectStyles'
66
import prefixSelector from '../util/prefixSelector'
77
import wrapWithVariants from '../util/wrapWithVariants'
88

9-
function defineRule(selector, properties) {
10-
const decls = _.map(properties, (value, property) => {
11-
return postcss.decl({
12-
prop: `${property}`,
13-
value: `${value}`,
14-
})
15-
})
16-
17-
return postcss.rule({ selector }).append(decls)
18-
}
19-
20-
function defineUtility(selector, properties, options) {
21-
if (selector.startsWith('.')) {
22-
return defineUtility(selector.slice(1), properties, options)
23-
}
24-
25-
const rule = defineRule(
26-
prefixSelector(options.prefix, `.${escapeClassName(selector)}`),
27-
properties
28-
)
29-
30-
if (options.important) {
31-
rule.walkDecls(decl => (decl.important = true))
32-
}
33-
34-
return rule
35-
}
36-
379
function parseStyles(styles) {
3810
if (!Array.isArray(styles)) {
3911
return parseStyles([styles])
4012
}
4113

42-
return _.flatMap(styles, (style) => style instanceof Node ? style : parseObjectStyles(style))
14+
return _.flatMap(styles, style => (style instanceof Node ? style : parseObjectStyles(style)))
4315
}
4416

4517
export default function(config) {
@@ -68,7 +40,7 @@ export default function(config) {
6840
}
6941

7042
if (options.respectImportant && _.get(config, 'options.important')) {
71-
rule.walkDecls(decl => decl.important = true)
43+
rule.walkDecls(decl => (decl.important = true))
7244
}
7345
})
7446

0 commit comments

Comments
 (0)