postcss-extend icon indicating copy to clipboard operation
postcss-extend copied to clipboard

Consider killing "anti-pattern" warning

Open timkelty opened this issue 10 years ago • 4 comments

Writing modular/BEM CSS can sometimes lead to this "anti-pattern" warning, when in fact it is perfectly logical.

In this example, we're extending .Component, even though it hasn't yet had any styles attached to it. Though it may, and we would want them once we added.

.Component--modifier {…}
.Component-descendant {…}

…
.ClonedComponent {
  @extend .Component;
  @extend .Component--modifier;
}

I think either totally removing the warning and putting something in the readme would suffice, otherwise maybe a setting to silence it.

timkelty avatar Jan 20 '16 13:01 timkelty

Going to make a pass at getting it to behave with BEM, but more than likely it will be silenced.

travco avatar Jan 26 '16 20:01 travco

At current, appears to be extending empty classes without complaint, no guarantee on the rest of BEM.

travco avatar Jun 21 '16 20:06 travco

For those coming here trying to clear up this warning, note that it will be thrown if there are subsequent declarations of the original extended class after @extend is used.

Easier to see the example than read the sentence above:

.column {
	width: calc(100% - 4rem);
	max-width: 70rem;
	margin: 0 auto;
}

.column--wide {
	@extend .column;
	max-width: 110rem;
}

.column--narrow {
	@extend .column;
	max-width: 45rem;
}

.column.with-aside {
	width: calc(100% - 20rem);
}

(This is also bad BEM, you'd probably want to replace the compound selector .column.with-aside to be .column--with-aside)

good-idea avatar Oct 07 '17 23:10 good-idea

@travco will this problem be solved?

higimo avatar Sep 19 '18 20:09 higimo