-
Notifications
You must be signed in to change notification settings - Fork 54
CSS tree validator with custom processor #1184
Conversation
|
||
module.exports = () => ({ | ||
code: input => | ||
input.replace(/-styled-mixin\d+:\s.+(?!{|,).$/gm, `/* styled-mixin */`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there any particular reason/preference why we are commenting out rather than removing the styled-mixin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh there is. By removing the line with the styled-mixin it can open a can of worms of linting errors such as having a selector with no styles e.g.
const example = css`
${({ height }) => height ? `height: ${height};` : ''}
`;
would produce
.selector1 {
}
and also having a semi-colon where you don't need one e.g.
const example = css`
width: 100%;
${({ height }) => height ? `height: ${height};` : ''}
`;
would produce
.selector1 {
width: 100%; <--- semi colon not needed
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty selector makes sense, that's not ideal. On the semi-colon is that suggesting the semi-colon's are only needed in CSS if there is a trailing statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's true but after investigation I realised it's bad practice to do that and the semi-colon error must have been related to something else.
@@ -0,0 +1,7 @@ | |||
// If this proposed functionality ever gets added https://github.com/styled-components/stylelint-processor-styled-components/issues/271 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it doesn't tell the CSS validator plugin to ignore those custom properties and rules. That's why the plugin has it's own ignore option which doesn't support regular expressions like stylelint's rules do. I have suggested this functionality in csstree/stylelint-validator
Doesn't require a testing from a tester. |
@jroebu14 please update and merge this. Thanks |
Resolves bbc/simorgh#2189
Overall change: Adds the
stylelint-csstree-validator
plugin to catch invalid CSS properties and values.A custom stylelint processor in the processors pipeline after
stylelint-processor-styled-components
comments outstyled-components
mixins so they don't failstylelint-csstree-validator
plugin validation.Code changes:
processorRemoveMixins
processorRemoveMixins
uses a regex to match and replace anystyled-components
mixin with the CSS comment/* styled-mixin */
because CSS comments are ignored by stylelinttest:lint:css
script inside of thetest
script to prevent committing invalid CSS.stylelint-processor-styled-components
is addedTesting notes
This doesn't require any testing because
stylelint
is developer dependency and doesn't modify any code used in production.