-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: add stylelint rule to ban concrete CSS rules inside theme files #10003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
// We use a regular `forEach`, instead of the PostCSS walker utils, | ||
// because we only care about the top-level nodes. | ||
root.nodes.forEach(node => { | ||
if (node.type === 'rule') { |
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.
One note here @jelbourn: this will capture Sass placeholder rules (e.g. %something {}
) which won't produce code unless they're extended. I opted to report them as well, because people can do things like %something, .something-else
which does produce CSS.
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.
I'm on board with that. We generally don't use placeholders (I think just a couple in button). I'm a fan of the greater control mixins give you about what's being rendered.
// We use a regular `forEach`, instead of the PostCSS walker utils, | ||
// because we only care about the top-level nodes. | ||
root.nodes.forEach(node => { | ||
if (node.type === 'rule') { |
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.
I'm on board with that. We generally don't use placeholders (I think just a couple in button). I'm a fan of the greater control mixins give you about what's being rendered.
stylelint-config.json
Outdated
@@ -13,6 +14,9 @@ | |||
"message": "The & operator is not allowed at the end of theme selectors.", | |||
"filePattern": "-theme\\.scss$" | |||
}], | |||
"material/no-concrete-rules": [true, { | |||
"filePattern": "-theme\\.scss$" |
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.
I would make this any partial file (starts with an underscore).
// We use a regular `forEach`, instead of the PostCSS walker utils, | ||
// because we only care about the top-level nodes. | ||
root.nodes.forEach(node => { | ||
if (node.type === 'rule') { |
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.
Could this also catch doing @include some-mixin()
in a partial?
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.
It could, but I'm not sure whether we want that. We have some cases where we use mixins inside the theme files to reduce duplication. We could make an exception for mixins that start with an underscore though.
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.
I mean specifically at the root level; @include
inside of another mixin would be fine.
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.
Done.
c53de7e
to
c697199
Compare
Addressed the feedback @jelbourn. Removing the "merge-safe" label, because I had to move some of the styling in the |
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.
LGTM
stylelint-config.json
Outdated
@@ -13,6 +14,9 @@ | |||
"message": "The & operator is not allowed at the end of theme selectors.", | |||
"filePattern": "-theme\\.scss$" | |||
}], | |||
"material/no-concrete-rules": [true, { | |||
"filePattern": "^_.*\\.scss$|-theme\\.scss$" |
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.
Why not just ^_.*\\.scss$
?
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.
I wanted to capture cases like something-theme.scss
, but I guess it's redundant since all the theme files are prefixed.
Adds a stylelint rule that will ensure that all of the CSS rules inside theme files are placed inside a mixin. This avoids style duplication whenever the file is imported. Relates to angular#9999.
c697199
to
ccba399
Compare
angular#10003) Adds a stylelint rule that will ensure that all of the CSS rules inside theme files are placed inside a mixin. This avoids style duplication whenever the file is imported. Relates to angular#9999.
angular#10003) Adds a stylelint rule that will ensure that all of the CSS rules inside theme files are placed inside a mixin. This avoids style duplication whenever the file is imported. Relates to angular#9999.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds a stylelint rule that will ensure that all of the CSS rules inside theme files are placed inside a mixin. This avoids style duplication whenever the file is imported.
Relates to #9999.