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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mm_eslint

v1.0.8

Published

ESLint plugin for naming conventions - PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules

Readme

MM ESLint Plugin

基于个人命名规范的ESLint插件,支持类名、函数名、变量名、常量名等命名规范检测。

功能特性

  • 类名检测 - 大驼峰命名法(PascalCase)
  • 函数名检测 - 小驼峰命名法(camelCase)
  • 方法名检测 - 小驼峰命名法(camelCase)
  • 变量名检测 - 小写蛇形命名法(snake_case)
  • 常量名检测 - 大写蛇形命名法(UPPER_SNAKE_CASE)
  • 私有成员检测 - 下划线开头的小写蛇形命名
  • 入参名检测 - 小写蛇形命名法(snake_case)
  • 属性名检测 - 基于值类型的多风格命名
  • 长度限制 - 所有命名长度限制在1-20字符
  • 单个单词优先 - 鼓励使用单个单词命名
  • 单词长度限制 - 每个单词限制在最大8字符
  • 禁止废话词 - 避免使用Manager、Handler等冗余词汇
  • JSDoc支持 - 集成JSDoc文档要求

安装

npm安装

npm install mm_eslint --save-dev

本地安装

如果您想使用本地版本,可以将插件文件复制到项目中:

# 复制插件文件到您的项目
cp mm_eslint/index.js your-project/eslint-plugins/

快速开始

1. 完整配置

在您的ESLint配置文件中引入插件:

// eslint.config.js
const namingConventionPlugin = require("mm_eslint");

module.exports = [
  {
    files: ["**/*.js"],
    plugins: {
      "naming-convention": namingConventionPlugin,
      jsdoc: require("eslint-plugin-jsdoc"),
    },
    rules: {
      // 自定义命名规范插件规则(优先使用)
      "naming-convention/class-name": "error",
      "naming-convention/function-name": "error",
      "naming-convention/method-name": "error",
      "naming-convention/variable-name": "warn",
      "naming-convention/constant-name": "error",
      "naming-convention/private-naming": "warn",
      "naming-convention/param-name": "warn",
      "naming-convention/property-name": "warn",

      // 禁用与命名规范插件冲突的默认规则
      camelcase: "off",
      "id-match": "off",
      "new-cap": "off",
      "id-length": "off",
      "id-denylist": "off",
      "id-blacklist": "off",
    },
  },

  {
    // 代码风格规则
    rules: {
      "max-len": ["error", { code: 100 }],
      indent: ["error", 2],
      quotes: ["error", "single"],
      "no-tabs": "error",
      semi: ["error", "always"],
    },
  },

  {
    // 错误处理规则
    rules: {
      "no-unused-vars": ["error", { args: "all" }],
      "no-unsafe-finally": "warn",
      "no-throw-literal": "error",
    },
  },

  {
    // 最佳实践规则
    rules: {
      "prefer-promise-reject-errors": "error",
      "no-param-reassign": "error",
      "prefer-object-spread": "error",
      "prefer-arrow-callback": "error",
      "max-lines-per-function": ["warn", { max: 40 }],
      complexity: ["warn", 10],
    },
  },

  {
    // JSDoc规则
    rules: {
      "jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
      "jsdoc/check-alignment": "warn",
      "jsdoc/check-indentation": "warn",
      "jsdoc/check-param-names": "warn",
      "jsdoc/check-syntax": "warn",
      "jsdoc/check-tag-names": "warn",
      "jsdoc/check-types": "warn",
      "jsdoc/no-undefined-types": "warn",
      "jsdoc/require-description": "warn",
      "jsdoc/require-param": "warn",
      "jsdoc/require-param-description": "warn",
      "jsdoc/require-param-name": "warn",
      "jsdoc/require-param-type": "warn",
      "jsdoc/require-returns": "warn",
      "jsdoc/require-returns-check": "warn",
      "jsdoc/require-returns-description": "warn",
      "jsdoc/require-returns-type": "warn",
      "jsdoc/valid-types": "warn",
    },
  },
];

2. 命令行使用

# 验证单个文件
npx eslint your-file.js

# 验证所有JS文件
npx eslint "**/*.js"

# 验证并自动修复
npx eslint --fix your-file.js

命名规范规则

类名规则(class-name)

  • 级别: error
  • 要求: 大驼峰命名法(PascalCase)
  • 长度: 1-20字符
  • 单词长度: 每个单词≤8字符
  • 示例: User, Product
  • 错误示例: UserConfiguration, ProductManagement

函数名规则(function-name)

  • 级别: error
  • 要求: 小驼峰命名法(camelCase)
  • 长度: 1-20字符
  • 单词长度: 每个单词≤8字符
  • 优先: 单个单词
  • 示例: get, getName, process
  • 错误示例: getConfiguration, processInformation

方法名规则(method-name)

  • 级别: error
  • 要求: 小驼峰命名法(camelCase)
  • 长度: 1-20字符
  • 单词长度: 每个单词≤8字符
  • 优先: 单个单词
  • 示例: add, setName, isValid
  • 错误示例: addConfiguration, validateAuthentication

变量名规则(variable-name)

  • 级别: warn
  • 要求: 小写蛇形命名法(snake_case)
  • 长度: 1-20字符
  • 示例: user_count, max_retry
  • 错误示例: userCount, MAX_RETRY

常量名规则(constant-name)

  • 级别: error
  • 要求: 大写蛇形命名法(UPPER_SNAKE_CASE)
  • 长度: 1-20字符
  • 示例: MAX_RETRY, DEFAULT_TIMEOUT
  • 错误示例: maxRetry, defaultTimeout

私有成员规则(private-naming)

  • 级别: warn
  • 要求: 下划线开头的小写蛇形命名
  • 长度: 2-20字符
  • 示例: _user_count, _internal_data
  • 错误示例: userCount, _UserCount

入参名规则(param-name)

  • 级别: warn
  • 要求: 小写蛇形命名法(snake_case)
  • 长度: 1-20字符
  • 示例: user_name, max_count
  • 错误示例: userName, maxCount

属性名规则(property-name)

  • 级别: warn
  • 要求: 基于值类型的多风格命名
  • 长度: 1-20字符
  • 示例: user_name(字符串), getUser(函数), User(类)

错误示例

// ❌ 错误的命名示例
class UserConfiguration {     // "Configuration"超过8字符
const getConfiguration = function() {}; // "Configuration"超过8字符
let maxRetryCount = 5;       // 变量名应该小写蛇形
const userCount = 10;        // 常量名应该大写蛇形

// ✅ 正确的命名示例
class User {
  constructor() {
    this._user_count = 0;    // 私有属性正确
  }

  /**
   * 获取用户数量
   * @returns {number} 用户数量
   */
  get() {                    // 方法名正确(单个单词≤8字符)
    return this._user_count;
  }
}

const MAX_RETRY = 5;         // 常量名正确
let user_count = 10;         // 变量名正确

单词长度验证

插件验证复合名称中的每个单词不超过8个字符:

  • 有效: UserService("User"=4, "Service"=7)
  • 无效: UserConfiguration("Configuration"=13 > 8)
  • 有效: getUser("get"=3, "User"=4)
  • 无效: getConfiguration("Configuration"=13 > 8)

配置选项

您可以通过配置自定义规则参数:

// 自定义配置示例
const customConfig = {
  "class-name": {
    regex: /^[A-Z][a-zA-Z]*$/,
    min: 1,
    max: 25, // 扩展最大长度
    single_word_len: 10, // 扩展单词长度限制
    message: "类名{name}必须使用大驼峰命名法",
  },
};

const detector = new NamingDetector(customConfig);

开发

项目结构

mm_eslint/
├── index.js          # 主插件文件
├── package.json      # npm配置
├── eslint.config.js  # ESLint配置
├── test.js           # 单元测试
├── example.js        # 使用示例
└── README.md         # 说明文档

运行测试

# 运行单元测试
npm test

# 运行ESLint检查
npm run lint

许可证

ISC License

贡献

欢迎提交Issue和Pull Request来改进这个插件。

更新日志

v1.1.0

  • 添加单词长度验证(每个单词最大8字符)
  • 添加入参名和属性名检测
  • 集成JSDoc文档要求
  • 增强配置,包含完整的ESLint规则

v1.0.0

  • 初始版本发布
  • 支持类名、函数名、方法名、变量名、常量名、私有成员命名规范检测
  • 支持长度限制和单个单词优先规则
  • 支持禁止废话词检测