If you want to implement this rule, you will need to develop it as a custom plugin. stylelint previously included a rule called selector-no-empty
which catered to this scenario, but it was removed in version 7.8.0. You can use the original rule as a reference to create your own plugin. The source code can be found here.
The reason behind the removal of the rule is documented in the change log:
The core functionality of stylelint does not include thorough validation against the CSS specification. It is recommended to explore csstree and css-values for such capabilities, and contribute to those projects or their associated stylelint plugins.
While there exists a csstree stylelint plugin for assessing the correctness of your CSS, the feature for selector validation is still in development. Therefore, consider utilizing the existing csstree stylelint plugin and await the incorporation of selector validation.
Keep in mind that stylelint primarily focuses on detecting potentially problematic code structures rather than enforcing CSS specifications. It offers rules like
declaration-block-no-shorthand-property-overrides
,
no-descending-specificity
,
no-duplicate-selectors
to identify possible issues. Additionally, it provides rules such as
unit-blacklist
,
selector-max-id
,
selector-class-pattern
to regulate the CSS features permitted within a project.