@bhollis/eslint-plugin-css-modules

中文文档
1.0.1发布于 2026/04/04MITES Module近 30 天下载 3.7万

Checks that you are using the existent css/scss/less classes, no more no less

原始使用文档
文档目录6 节
  1. Rules
  2. Installation
  3. Usage:
  4. Specifying base path
  5. Screen Shot
  6. With Thanks

@bhollis/eslint-plugin-css-modules

This plugin intends to help you in tracking down problems when you are using css-modules. It tells if you are using a non-existent css/scss/less class in js or if you forgot to use some classes which you declared in css/scss/less.

This is a forked version of https://github.com/atfzl/eslint-plugin-css-modules with fixes to make it compatible with more recent versions of css-loader, especially with namedExports: true. It is also compatible with ESLint's flat config.

Rules

  • css-modules/no-unused-class: You must use all the classes defined in css/scss/less file.

If you still want to mark a class as used, then use this comment on top of your file

/* eslint css-modules/no-unused-class: [2, { markAsUsed: ['container'] }] */

where container is the css class that you want to mark as used. Add all such classes in the array.

If you use the camelCase option of css-loader, you must also enabled it for this plugin

/* eslint css-modules/no-unused-class: [2, { camelCase: true }] */
  • css-modules/no-undef-class: You must not use a non existing class, or a property that hasn't been exported using the :export keyword.

If you use the camelCase option of css-loader, you must also enabled it for this plugin

/* eslint css-modules/no-undef-class: [2, { camelCase: true }] */

Installation

npm i --save-dev @bhollis/eslint-plugin-css-modules

Usage:

// eslint.config.js
import { defineConfig } from "eslint/config";
import cssModules from "@bhollis/eslint-plugin-css-modules";

export default defineConfig([
  cssModules.configs.recommended
    {
        files: ["**/*.jsx"], // any patterns you want to apply the config to
        plugins: {
            'css-modules': cssModules,
        },
        extends: ["css-modules/recommended"],
    },
]);

You may also tweak the rules individually. For instance, if you use the camelCase option of webpack's css-loader:

// eslint.config.js
import { defineConfig } from "eslint/config";
import cssModules from "@bhollis/eslint-plugin-css-modules";

export default defineConfig([
    {
        files: ["**/*.jsx"], // any patterns you want to apply the config to
        plugins: {
            'css-modules': cssModules,
        },
        rules: {
      "css-modules/no-unused-class": [2, { "camelCase": true }],
      "css-modules/no-undef-class": [2, { "camelCase": true }]
    },
    },
]);

The camelCase option has 4 possible values, see css-loader#camelCase for description:

true | "dashes" | "only" | "dashes-only"

Specifying base path

You can specify path for the base directory via plugin settings in eslint.config.js. This is used by the plugin to resolve absolute (S)CSS paths:

// eslint.config.js
import { defineConfig } from "eslint/config";
import cssModules from "@bhollis/eslint-plugin-css-modules";

export default defineConfig([
    {
        files: ["**/*.jsx"], // any patterns you want to apply the config to
        plugins: {
            'css-modules': cssModules,
        },
        settings: {
      'css-modules': {
        basePath: "app/scripts/..."
      }
    },
    },
]);

Screen Shot

ScreenShot

   1:8   error  Unused classes found: container  css-modules/no-unused-class
   5:17  error  Class 'containr' not found       css-modules/no-undef-class
  10:26  error  Class 'foo' not found            css-modules/no-undef-class

scss:

/* .head is global, will not be used in js */
:global(.head) {
  color: green;
}

.container {
  width: 116px;

  i {
    font-size: 2.2rem;
  }

  .button {
    padding: 7px 0 0 5px;
  }
}

.footer {
  color: cyan;
}

With Thanks

版本与发布记录

@bhollis/eslint-plugin-css-modules 共发布 2 个版本,首次发布于 2025/12/03;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.1latest2026/04/047 个月前
1.0.02025/12/0311 个月前

关于 @bhollis/eslint-plugin-css-modules 的常见问题

@bhollis/eslint-plugin-css-modules 是什么?

Checks that you are using the existent css/scss/less classes, no more no less

如何安装 @bhollis/eslint-plugin-css-modules?

在项目目录运行 npm install @bhollis/eslint-plugin-css-modules,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(>=2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bhollis/eslint-plugin-css-modules 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bhollis__eslint-plugin-css-modules 是否存在。

@bhollis/eslint-plugin-css-modules 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bhollis/eslint-plugin-css-modules 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bhollis/eslint-plugin-css-modules 可以商用吗?

@bhollis/eslint-plugin-css-modules 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bhollis/eslint-plugin-css-modules 的下载量有多少?

根据 npm 官方下载统计,@bhollis/eslint-plugin-css-modules 在 2026/10/08 – 2026/11/06 这 30 天内被下载 36,606 次,日均约 1,220 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bhollis/eslint-plugin-css-modules 还在维护吗?

最新版本 1.0.1 发布于 2026/04/04(7 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/12/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。