This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1184 from bbc/add-css-validator
CSS tree validator with custom processor
- Loading branch information
Showing
8 changed files
with
168 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
{ | ||
"rules": { | ||
"declaration-no-important": true | ||
"declaration-no-important": true, | ||
"csstree/validator": true | ||
}, | ||
"processors": [["stylelint-processor-styled-components", { | ||
"parserPlugins": [ | ||
"jsx", | ||
"exportDefaultFrom" | ||
] | ||
}]], | ||
"processors": [ | ||
[ | ||
"stylelint-processor-styled-components", { | ||
"parserPlugins": [ | ||
"jsx", | ||
"exportDefaultFrom" | ||
] | ||
} | ||
], | ||
"./lib/stylelint/processorRemoveMixins.js" | ||
], | ||
"extends": [ | ||
"stylelint-config-recommended", | ||
"stylelint-config-styled-components" | ||
], | ||
"plugins": [ | ||
"stylelint-csstree-validator" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// If this proposed functionality ever gets added https://github.com/styled-components/stylelint-processor-styled-components/issues/271 | ||
// then please delete this processor and any use of it. | ||
|
||
module.exports = () => ({ | ||
code: input => | ||
input.replace(/-styled-mixin\d+:\s.+(?!{|,).$/gm, `/* styled-mixin */`), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const processorRemoveMixins = require('./processorRemoveMixins'); | ||
|
||
it('should comment out styled-components mixin styles', () => { | ||
const input = ` | ||
.selector78 { | ||
list-style-type: none; | ||
margin: $dummyValue 0 0 0; | ||
-styled-mixin1: dummyValue; | ||
-styled-mixin2: dummyValue; | ||
padding: 0; | ||
} | ||
`; | ||
const actual = processorRemoveMixins().code(input); | ||
const expected = ` | ||
.selector78 { | ||
list-style-type: none; | ||
margin: $dummyValue 0 0 0; | ||
/* styled-mixin */ | ||
/* styled-mixin */ | ||
padding: 0; | ||
} | ||
`; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should comment out styled-components mixins styles in media queries', () => { | ||
const input = ` | ||
.selector78 { | ||
list-style-type: none; | ||
margin: $dummyValue 0 0 0; | ||
-styled-mixin1: dummyValue; | ||
-styled-mixin2: dummyValue; | ||
padding: 0; | ||
@media (min-width: $dummyValue) { | ||
margin: $dummyValue 0 0 0; | ||
-styled-mixin3: dummyValue; | ||
} | ||
} | ||
`; | ||
const actual = processorRemoveMixins().code(input); | ||
const expected = ` | ||
.selector78 { | ||
list-style-type: none; | ||
margin: $dummyValue 0 0 0; | ||
/* styled-mixin */ | ||
/* styled-mixin */ | ||
padding: 0; | ||
@media (min-width: $dummyValue) { | ||
margin: $dummyValue 0 0 0; | ||
/* styled-mixin */ | ||
} | ||
} | ||
`; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should comment out styled-components mixins styles without semi-colons', () => { | ||
const input = ` | ||
.selector78 { | ||
list-style-type: none; | ||
margin: $dummyValue 0 0 0; | ||
-styled-mixin1: dummyValue; | ||
-styled-mixin2: dummyValue; | ||
-styled-mixin3: dummyValue | ||
padding: 0; | ||
-styled-mixin4: dummyValue | ||
} | ||
`; | ||
const actual = processorRemoveMixins().code(input); | ||
const expected = ` | ||
.selector78 { | ||
list-style-type: none; | ||
margin: $dummyValue 0 0 0; | ||
/* styled-mixin */ | ||
/* styled-mixin */ | ||
/* styled-mixin */ | ||
padding: 0; | ||
/* styled-mixin */ | ||
} | ||
`; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should not comment out styled-components mixins selectors', () => { | ||
const input = ` | ||
-styled-mixin1:hover &, | ||
-styled-mixin4:focus & { | ||
-styled-mixin5: dummyValue | ||
text-decoration: none; | ||
border-bottom: $dummyValue solid $dummyValue; | ||
-styled-mixin1: 0; | ||
} | ||
`; | ||
const actual = processorRemoveMixins().code(input); | ||
const expected = ` | ||
-styled-mixin1:hover &, | ||
-styled-mixin4:focus & { | ||
/* styled-mixin */ | ||
text-decoration: none; | ||
border-bottom: $dummyValue solid $dummyValue; | ||
/* styled-mixin */ | ||
} | ||
`; | ||
|
||
expect(actual).toEqual(expected); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ const StyledListItem = styled.li` | |
` | ||
: css` | ||
right: 0; | ||
`}; | ||
`} | ||
} | ||
`; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters