npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@simonsmith/stylelint-component-custom-property

v2.1.0

Published

Stylelint plugin that validates CSS custom properties in CSS modules to ensure they follow a component-based naming convention.

Readme

stylelint-component-custom-property

Stylelint plugin that validates CSS custom properties in CSS modules to ensure they follow a component-based naming convention.

npm version CI

Why?

When working with CSS modules, components often expose custom properties as a public API that can be overridden by parent components. This plugin validates that these public custom properties follow a consistent naming convention based on the component name.

For example, if your CSS module is named Button.module.css:

.button {
  /* Public API - validated */
  background-color: var(--Button-primary-color, #007bff);

  /* Private properties - not validated */
  --internal-state: active;
}

This convention helps with:

  • Consistency: All public custom properties follow the same naming pattern
  • Clarity: It's immediately clear which properties are part of the component's public API
  • Avoiding conflicts: Prevents naming collisions when components are nested
  • API documentation: Fallback values serve as default values and documentation

Installation

npm install --save-dev @simonsmith/stylelint-component-custom-property
yarn add --dev @simonsmith/stylelint-component-custom-property
pnpm add --save-dev @simonsmith/stylelint-component-custom-property

Usage

Add the plugin to your stylelint configuration:

{
  "plugins": ["@simonsmith/stylelint-component-custom-property"],
  "rules": {
    "@simonsmith/stylelint-component-custom-property": true
  }
}

Configuration

The rule accepts different validation types:

Basic validation (default)

Validates only that custom properties match the component name from the filename:

{
  "plugins": ["@simonsmith/stylelint-component-custom-property"],
  "rules": {
    "@simonsmith/stylelint-component-custom-property": true
  }
}

SUIT CSS validation

Validates SUIT CSS naming conventions:

{
  "plugins": ["@simonsmith/stylelint-component-custom-property"],
  "rules": {
    "@simonsmith/stylelint-component-custom-property": {
      "validationType": "suitcss"
    }
  }
}

Due to the potential ambiguity of the validation pattern in SUIT CSS this option prefers to lean on being more relaxed rather than incorrectly flagging properties as invalid. See the unit tests for what it covers currently

Custom pattern validation

Use your own regular expression for suffix validation:

{
  "plugins": ["@simonsmith/stylelint-component-custom-property"],
  "rules": {
    "@simonsmith/stylelint-component-custom-property": {
      "validationType": /^-[a-z][a-zA-Z]*$/
    }
  }
}

Disable the rule

{
  "rules": {
    "@simonsmith/stylelint-component-custom-property": false
  }
}

How it works

The plugin:

  • Only applies to CSS modules - files ending with .module.css
  • Validates public API custom properties - ensures they start with --ComponentName-
  • Ignores private custom properties - allows any naming for internal use
  • Autofix - can automatically correct invalid prefixes in API declarations

What gets validated

The plugin validates custom properties only when they're used as public API declarations.

API declarations (validated)

Custom properties used in var() functions with fallback values are treated as component API declarations:

.container {
  gap: var(--Button-spacing, 1rem);
  width: var(--Button-max-width, 320px);
}

Private properties (ignored)

Direct custom property assignments are considered private implementation details:

.button {
  --internal-state: hover;
  --computed-size: calc(100% - 2rem);
}

Property consumption (ignored)

Custom properties used without fallbacks are considered consumption of existing properties:

.button {
  color: var(--theme-primary);
  margin: var(--Button-spacing);
}

Examples

Valid

Button.module.css

.button {
  /* Public API declarations - validated */
  background-color: var(--Button-primary-color, #007bff);
  padding: var(--Button-padding, 0.5rem 1rem);

  /* Private properties - not validated */
  --internal-state: default;
  --computed-width: calc(100% - 2rem);

  /* Consuming existing properties - not validated */
  margin: var(--global-spacing);
  font-family: var(--theme-font);
}

/* Overriding child component APIs - not validated */
.button-container {
  --Icon-size: 16px;
  --Tooltip-background: var(--Button-primary-color);
}

Invalid

Button.module.css

.button {
  /* Wrong prefix in API declaration */
  background: var(--wrong-color, red);

  /* No prefix in API declaration */
  padding: var(--spacing, 1rem);
}

Autofix

The plugin supports stylelint's --fix option and will automatically correct invalid custom property prefixes in API declarations:

stylelint "**/*.module.css" --fix

License

MIT