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
CSS tree validator with custom processor #1184
Merged
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6e3617b
WIP - css validator with custom processor
7a28d7d
rename custom stylelint processor
180e5f5
add test for custom stylelint processor
7debac2
fix stylelint errors
d680511
add husky hooks back in
eca6133
Merge branch 'latest' into add-css-validator
889bd5c
update package-lock
7cf32df
update regex to not match mixin selectors
92a35f2
split out test cases
f7c86c7
add missing semi-colon
32a6e55
comment about potential to remove custom processor
86ce13e
Merge branch 'latest' into add-css-validator
37313b6
Merge branch 'latest' into add-css-validator
fc2f8f5
Merge branch 'latest' into add-css-validator
f45a8d1
Merge branch 'latest' into add-css-validator
483c344
Merge branch 'latest' into add-css-validator
904ef58
Merge branch 'latest' into add-css-validator
f95c08d
Merge branch 'latest' into add-css-validator
PriyaKR e1a1c86
Merge branch 'latest' into add-css-validator
amywalkerdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 +1,14 @@ | ||
{ | ||
"rules": { | ||
"declaration-no-important": true | ||
"declaration-no-important": true, | ||
"csstree/validator": true | ||
}, | ||
"processors": ["stylelint-processor-styled-components"], | ||
"processors": ["stylelint-processor-styled-components", "./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,4 @@ | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
would produce
and also having a semi-colon where you don't need one e.g.
would produce
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.