This Stylelint rule, `stylelint-selector-no-utility`, is designed to enforce a specific coding standard by disallowing the direct styling of utility classes within CSS. It serves to protect the immutability of single-purpose utility styles, preventing unintended side effects that can arise from altering their definitions. The rule is highly specialized and is intended for use with `@primer/css`, the CSS framework developed by GitHub. The current stable release is version 4.0.0, which was published in March 2019. Due to its close integration with the Primer CSS ecosystem, the package's release cadence is not frequent and is typically tied to updates or changes within Primer CSS itself. Its primary differentiator lies in its targeted application to enforce best practices within a utility-first CSS architecture, specifically for projects utilizing `@primer/css`. It acts as a guardrail against common anti-patterns that can compromise the predictability and maintainability of utility-based styling.
npm install stylelint-selector-no-utilityVerified import paths — ran on the pinned version, not inferred.
This configuration snippet shows how to register the `stylelint-selector-no-utility` plugin and enable its `primer/selector-no-utility` rule in a `.stylelintrc.json` file.
Ensure `@primer/css` (version `>=12`) is installed in your project alongside `stylelint-selector-no-utility`. For example: `npm install @primer/css@^12`.
If using v3.0.1, install `@primer/css@canary`. Otherwise, upgrade to v4.0.0 or later and install the stable `@primer/css` (version `>=12`).
Be aware that the effectiveness and relevance of this rule outside of a Primer CSS context may be limited. Custom adaptations would be required for other utility-first frameworks.
Add `'stylelint-selector-no-utility'` to the `plugins` array in your Stylelint configuration file (e.g., `.stylelintrc.json` or `stylelint.config.js`).
Install the package using npm or yarn: `npm install --save-dev stylelint-selector-no-utility` or `yarn add --dev stylelint-selector-no-utility`.
Install the `@primer/css` package: `npm install @primer/css@^12` or `yarn add @primer/css@^12`.