A stylelint plugin to disallow certain tags without a class qualifier in selectors.
For example, if this rule is configured for (only) the
<div> tag, the following patterns are considered violations:
The following patterns are not considered violations:
/* (tag is qualified with a class) */
/* (rule not configured for '<a>' tag) */
According to the HTML specification, tags like
<span> do no inherently represent anything. It would therefore be strange to attach styling to such a generic container, even within a given context. We believe that tags like
<span> should only have meaning (and thus receive corresponding style rules) when they have a class as an additional qualifier.
Install this package as a development dependency using NPM:
npm install --save-dev stylelint-selector-tag-no-without-class
Add the plugin and the corresponding rule to the stylelint configuration file, and configure the tags that should not be used as a selector without a qualifying classname:
// .stylelintrc"plugins":"stylelint-selector-tag-no-without-class""rules":"plugin/selector-tag-no-without-class": "div" "span"
["array", "of", "tags", "or", "/regexes/"]|"tag"|"/regex/"
Specification of tags that should not occur without a class qualifier. If a string is surrounded with
"/", it is interpreted as a regular expression. For example,
"^/h\d+$/" disallows using any section heading without a class qualifier.
This plugin is released under the MIT license.