Skip to content

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

Merged
merged 1 commit into from
Feb 26, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Feb 18, 2018

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.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 18, 2018
// 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') {
Copy link
Member Author

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.

Copy link
Member

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') {
Copy link
Member

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.

@@ -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$"
Copy link
Member

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') {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@crisbeto crisbeto force-pushed the concrete-css-rules-rule branch 2 times, most recently from c53de7e to c697199 Compare February 19, 2018 19:46
@crisbeto
Copy link
Member Author

Addressed the feedback @jelbourn. Removing the "merge-safe" label, because I had to move some of the styling in the button.scss around.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -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$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just ^_.*\\.scss$?

Copy link
Member Author

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.

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Feb 20, 2018
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.
@crisbeto crisbeto force-pushed the concrete-css-rules-rule branch from c697199 to ccba399 Compare February 20, 2018 17:57
@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Feb 20, 2018
@jelbourn jelbourn merged commit d078e5e into angular:master Feb 26, 2018
mmalerba pushed a commit to mmalerba/components that referenced this pull request Feb 26, 2018
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.
jelbourn pushed a commit to jelbourn/components that referenced this pull request Feb 27, 2018
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-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants