Skip to content

Commit b2e5030

Browse files
committed
perf: linting
1 parent 3db6da5 commit b2e5030

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

src/index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import postcss from 'postcss';
33
const filter = (filter, attributeSelector) => new RegExp(filter.map(attribut => `^\\[${attribut}`).join('|')).test(attributeSelector);
44

55
export default postcss.plugin('postcss-attribute-selector-prefix', options => {
6-
return nodes => {
7-
return nodes.walkRules(rule => {
8-
rule.selector = rule.selector.replace(/\[.*?]/g, match => {
9-
if (options.prefix === undefined) {
10-
return match;
11-
}
6+
return nodes => {
7+
return nodes.walkRules(rule => {
8+
rule.selector = rule.selector.replace(/\[.*?]/g, match => {
9+
if (options.prefix === undefined) {
10+
return match;
11+
}
1212

13-
if (options.filter !== undefined && filter(options.filter, match) === false) {
14-
return match;
15-
}
13+
if (options.filter !== undefined && filter(options.filter, match) === false) {
14+
return match;
15+
}
1616

17-
if (options.ignore !== undefined && filter(options.ignore, match) === true) {
18-
return match;
19-
}
17+
if (options.ignore !== undefined && filter(options.ignore, match) === true) {
18+
return match;
19+
}
2020

21-
return match.replace(/(\[.*?="?)(.*?)("?])/, (match, before, requireds, after) => {
22-
return `${before}${requireds.split(' ').map(required => options.prefix + required).join(' ')}${after}`;
23-
});
24-
});
25-
});
26-
};
21+
return match.replace(/(\[.*?="?)(.*?)("?])/, (match, before, requireds, after) => {
22+
return `${before}${requireds.split(' ').map(required => options.prefix + required).join(' ')}${after}`;
23+
});
24+
});
25+
});
26+
};
2727
});

test/test-plugin.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
11
import test from 'ava';
22
import postcss from 'postcss';
3-
import plugin from '../src/';
3+
import plugin from '../src';
44

55
const processing = (inputCSS, options) => postcss([plugin(options)]).process(inputCSS).css;
66

77
test('processing not options and not attribute selector', t => {
8-
const expected = '.class, .test { color:red; }';
9-
const fixtures = '.class, .test { color:red; }';
10-
t.is(processing(fixtures), expected);
8+
const expected = '.class, .test { color:red; }';
9+
const fixtures = '.class, .test { color:red; }';
10+
t.is(processing(fixtures), expected);
1111
});
1212

1313
test('processing options prefix and not attribute selector', t => {
14-
const expected = '.class { color:red; }';
15-
const fixtures = '.class { color:red; }';
16-
t.is(processing(fixtures, {prefix: 'test-'}), expected);
14+
const expected = '.class { color:red; }';
15+
const fixtures = '.class { color:red; }';
16+
t.is(processing(fixtures, {prefix: 'test-'}), expected);
1717
});
1818

1919
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; }';
22-
t.is(processing(fixtures, {prefix: 'test-'}), expected);
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; }';
22+
t.is(processing(fixtures, {prefix: 'test-'}), expected);
2323
});
2424

2525
test('processing options prefix and attribute selector', t => {
26-
const expected = '.class, [type="test-text"] { color:red; }';
27-
const fixtures = '.class, [type="text"] { color:red; }';
28-
t.is(processing(fixtures, {prefix: 'test-'}), expected);
26+
const expected = '.class, [type="test-text"] { color:red; }';
27+
const fixtures = '.class, [type="text"] { color:red; }';
28+
t.is(processing(fixtures, {prefix: 'test-'}), expected);
2929
});
3030

3131
test('processing options prefix, filter and attribute selector', t => {
32-
const expected = '.class, [type="text"], [class*="test-lorem"] { color:red; }';
33-
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
34-
t.is(processing(fixtures, {
35-
prefix: 'test-',
36-
filter: ['class']
37-
}), expected);
32+
const expected = '.class, [type="text"], [class*="test-lorem"] { color:red; }';
33+
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
34+
t.is(processing(fixtures, {
35+
prefix: 'test-',
36+
filter: ['class']
37+
}), expected);
3838
});
3939

4040
test('processing options prefix, filter and attribute selector witch indentical class filter', t => {
41-
const expected = '.class, [type="text"], [alt*="class"] { color:red; }';
42-
const fixtures = '.class, [type="text"], [alt*="class"] { color:red; }';
43-
t.is(processing(fixtures, {
44-
prefix: 'test-',
45-
filter: ['class']
46-
}), expected);
41+
const expected = '.class, [type="text"], [alt*="class"] { color:red; }';
42+
const fixtures = '.class, [type="text"], [alt*="class"] { color:red; }';
43+
t.is(processing(fixtures, {
44+
prefix: 'test-',
45+
filter: ['class']
46+
}), expected);
4747
});
4848

4949
test('processing options filter and attribute selector', t => {
50-
const expected = '.class, [type="text"], [class*="lorem"] { color:red; }';
51-
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
52-
t.is(processing(fixtures, {
53-
filter: ['class']
54-
}), expected);
50+
const expected = '.class, [type="text"], [class*="lorem"] { color:red; }';
51+
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
52+
t.is(processing(fixtures, {
53+
filter: ['class']
54+
}), expected);
5555
});
5656

5757
test('processing options prefix, filter, ignore and attribute selector', t => {
58-
const expected = '.class, [type="text"], [class*="lorem"] { color:red; }';
59-
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);
58+
const expected = '.class, [type="text"], [class*="lorem"] { color:red; }';
59+
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);
6565
});
6666

6767
test('processing options prefix, ignore and attribute selector', t => {
68-
const expected = '.class, [type="text"], [class*="test-lorem"] { color:red; }';
69-
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
70-
t.is(processing(fixtures, {
71-
prefix: 'test-',
72-
ignore: ['type']
73-
}), expected);
68+
const expected = '.class, [type="text"], [class*="test-lorem"] { color:red; }';
69+
const fixtures = '.class, [type="text"], [class*="lorem"] { color:red; }';
70+
t.is(processing(fixtures, {
71+
prefix: 'test-',
72+
ignore: ['type']
73+
}), expected);
7474
});

0 commit comments

Comments
 (0)