Skip to content

Commit cd6c381

Browse files
committed
style: prettier
1 parent 3243d30 commit cd6c381

File tree

2 files changed

+66
-31
lines changed

2 files changed

+66
-31
lines changed

src/index.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import postcss from 'postcss';
22

3-
const filter = (filter, attributeSelector) => new RegExp(filter.map(attribut => `^\\[${attribut}`).join('|')).test(attributeSelector);
3+
const filter = (filter, attributeSelector) =>
4+
new RegExp(filter.map(attribut => `^\\[${attribut}`).join('|')).test(
5+
attributeSelector
6+
);
47

58
export default postcss.plugin('postcss-attribute-selector-prefix', options => {
69
return nodes => {
@@ -10,17 +13,29 @@ export default postcss.plugin('postcss-attribute-selector-prefix', options => {
1013
return match;
1114
}
1215

13-
if (options.filter !== undefined && filter(options.filter, match) === false) {
16+
if (
17+
options.filter !== undefined &&
18+
filter(options.filter, match) === false
19+
) {
1420
return match;
1521
}
1622

17-
if (options.ignore !== undefined && filter(options.ignore, match) === true) {
23+
if (
24+
options.ignore !== undefined &&
25+
filter(options.ignore, match) === true
26+
) {
1827
return match;
1928
}
2029

21-
return match.replace(/(\[.*?="?)(.*?)("?])/, (match, before, requireds, after) => {
22-
return `${before}${requireds.split(' ').map(required => options.prefix + required).join(' ')}${after}`;
23-
});
30+
return match.replace(
31+
/(\[.*?="?)(.*?)("?])/,
32+
(match, before, requireds, after) => {
33+
return `${before}${requireds
34+
.split(' ')
35+
.map(required => options.prefix + required)
36+
.join(' ')}${after}`;
37+
}
38+
);
2439
});
2540
});
2641
};

test/test-plugin.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import test from 'ava';
22
import postcss from 'postcss';
33
import plugin from '../src';
44

5-
const processing = (inputCSS, options) => postcss([plugin(options)]).process(inputCSS).css;
5+
const processing = (inputCSS, options) =>
6+
postcss([plugin(options)]).process(inputCSS).css;
67

78
test('processing not options and not attribute selector', t => {
89
const expected = '.class, .test { color:red; }';
@@ -17,8 +18,10 @@ test('processing options prefix and not attribute selector', t => {
1718
});
1819

1920
test('processing options prefix multiple', t => {
20-
const expected = '.class, [type="test-text"], [class*="test-lorem-1 test-lorem-2"], [id^="test-myID"] { color:red; }';
21-
const fixtures = '.class, [type="text"], [class*="lorem-1 lorem-2"], [id^="myID"] { color:red; }';
21+
const expected =
22+
'.class, [type="test-text"], [class*="test-lorem-1 test-lorem-2"], [id^="test-myID"] { color:red; }';
23+
const fixtures =
24+
'.class, [type="text"], [class*="lorem-1 lorem-2"], [id^="myID"] { color:red; }';
2225
t.is(processing(fixtures, {prefix: 'test-'}), expected);
2326
});
2427

@@ -29,46 +32,63 @@ test('processing options prefix and attribute selector', t => {
2932
});
3033

3134
test('processing options prefix, filter and attribute selector', t => {
32-
const expected = '.class, [type="text"], [class*="test-lorem"] { color:red; }';
35+
const expected =
36+
'.class, [type="text"], [class*="test-lorem"] { color:red; }';
3337
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
34-
t.is(processing(fixtures, {
35-
prefix: 'test-',
36-
filter: ['class']
37-
}), expected);
38+
t.is(
39+
processing(fixtures, {
40+
prefix: 'test-',
41+
filter: ['class']
42+
}),
43+
expected
44+
);
3845
});
3946

4047
test('processing options prefix, filter and attribute selector witch indentical class filter', t => {
4148
const expected = '.class, [type="text"], [alt*="class"] { color:red; }';
4249
const fixtures = '.class, [type="text"], [alt*="class"] { color:red; }';
43-
t.is(processing(fixtures, {
44-
prefix: 'test-',
45-
filter: ['class']
46-
}), expected);
50+
t.is(
51+
processing(fixtures, {
52+
prefix: 'test-',
53+
filter: ['class']
54+
}),
55+
expected
56+
);
4757
});
4858

4959
test('processing options filter and attribute selector', t => {
5060
const expected = '.class, [type="text"], [class*="lorem"] { color:red; }';
5161
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
52-
t.is(processing(fixtures, {
53-
filter: ['class']
54-
}), expected);
62+
t.is(
63+
processing(fixtures, {
64+
filter: ['class']
65+
}),
66+
expected
67+
);
5568
});
5669

5770
test('processing options prefix, filter, ignore and attribute selector', t => {
5871
const expected = '.class, [type="text"], [class*="lorem"] { color:red; }';
5972
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
60-
t.is(processing(fixtures, {
61-
prefix: 'test',
62-
filter: ['class'],
63-
ignore: ['class']
64-
}), expected);
73+
t.is(
74+
processing(fixtures, {
75+
prefix: 'test',
76+
filter: ['class'],
77+
ignore: ['class']
78+
}),
79+
expected
80+
);
6581
});
6682

6783
test('processing options prefix, ignore and attribute selector', t => {
68-
const expected = '.class, [type="text"], [class*="test-lorem"] { color:red; }';
84+
const expected =
85+
'.class, [type="text"], [class*="test-lorem"] { color:red; }';
6986
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
70-
t.is(processing(fixtures, {
71-
prefix: 'test-',
72-
ignore: ['type']
73-
}), expected);
87+
t.is(
88+
processing(fixtures, {
89+
prefix: 'test-',
90+
ignore: ['type']
91+
}),
92+
expected
93+
);
7494
});

0 commit comments

Comments
 (0)