Skip to content

Commit 7ef3b6a

Browse files
committed
Add excluding rules
1 parent 33a55bb commit 7ef3b6a

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ postcss([ require('postcss-flexibility') ])
3838

3939
See [PostCSS] docs for examples for your environment.
4040

41+
### Excluding rules
42+
43+
You can exclude rule from transformation by adding `/* flexibility-disable */` comment.
44+
45+
```css
46+
.foo {
47+
/* flexibility-disable */
48+
display: flex;
49+
}
50+
```
51+
will be processed to:
52+
```css
53+
.foo {
54+
/* flexibility-disable */
55+
display: flex;
56+
}
57+
```
4158

4259
--
4360

index.js

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

33
const postcssFlexibility = postcss.plugin('postcss-flexibility', () => css => {
44
css.walkRules(rule => {
5-
const jsDisplayExist = rule.some(({prop}) => prop === '-js-display');
5+
const isDisabled = rule.some(({prop, text}) =>
6+
prop === '-js-display' || text === 'flexibility-disable'
7+
);
68

7-
if (!jsDisplayExist) {
9+
if (!isDisabled) {
810
rule.walkDecls('display', decl => {
911
const {value} = decl;
1012
if (value === 'flex') {

test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import plugin from './';
66
function run(t, input, output) {
77
return postcss([plugin()]).process(input)
88
.then(result => {
9-
t.same(result.css, output);
10-
t.same(result.warnings().length, 0);
9+
t.deepEqual(result.css, output);
10+
t.deepEqual(result.warnings().length, 0);
1111
});
1212
}
1313

@@ -37,3 +37,17 @@ test('Don\'add "-js-display: flex" if it\'s already exist', t => {
3737
}`
3838
);
3939
});
40+
41+
test('Don\'add "-js-display: flex" if comment "flexibility-disable" is exist', t => {
42+
return run(
43+
t,
44+
`a {
45+
/* flexibility-disable */
46+
display: flex;
47+
}`,
48+
`a {
49+
/* flexibility-disable */
50+
display: flex;
51+
}`
52+
);
53+
});

0 commit comments

Comments
 (0)