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

mm_eslint

v1.7.1

Published

ESLint plugin for personal naming conventions - supports PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules with intelligent recommendations

Downloads

4,128

Readme

MM ESLint Plugin

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

npm version License: ISC Node.js Version Downloads GitHub stars

功能特性

  • 类名检测 - 大驼峰命名法(PascalCase)
  • 类实例名检测 - 小驼峰命名法(camelCase)
  • 函数名检测 - 小驼峰命名法(camelCase)
  • 参数名检测 - 小写蛇形命名法(snake_case)
  • 变量名检测 - 小写蛇形命名法(snake_case)
  • 常量名检测 - 大写蛇形命名法(UPPER_SNAKE_CASE)
  • 长度限制 - 所有命名长度限制在1-20字符
  • 单词长度限制 - 每个单词限制在最大8字符
  • 禁止废话词 - 避免使用Manager、Handler等冗余词汇
  • 命名推荐功能 - 推荐更短的替代名称,同时保持语义不变

实际支持的规则

插件实际支持以下ESLint规则:

  • mm_eslint/class-name - 类名检测
  • mm_eslint/class-instance-name - 类实例名检测
  • mm_eslint/function-name - 函数名检测
  • mm_eslint/param-name - 参数名检测
  • mm_eslint/variable-name - 变量名检测
  • mm_eslint/constant-name - 常量名检测

安装

npm安装

npm install mm_eslint --save-dev

本地安装

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

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

快速开始

1. 基本配置

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

// eslint.config.js
const mmEslint = require('mm_eslint');

module.exports = [
  {
    files: ['**/*.js'],
    plugins: {
      mm_eslint: {
        rules: mmEslint
      }
    },
    rules: {
      // 命名规范插件规则
      'mm_eslint/class-name': 'error',
      'mm_eslint/class-instance-name': 'error',
      'mm_eslint/function-name': 'error',
      'mm_eslint/param-name': 'warn',
      'mm_eslint/variable-name': 'warn',
      'mm_eslint/constant-name': 'error',

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

2. 命令行使用

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

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

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

命名规范规则

类名规则(class-name)

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

类实例名规则(class-instance-name)

  • 级别: error
  • 要求: 小驼峰命名法(camelCase)
  • 长度: 1-20字符
  • 单词长度: 每个单词≤8字符
  • 示例: userInstance, dbConn
  • 错误示例: UserInstance, db_conn, DB_CONN

函数名规则(function-name)

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

参数名规则(param-name)

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

变量名规则(variable-name)

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

常量名规则(constant-name)

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

错误示例

// ❌ 错误的命名示例
class user {}                           // 类名应该使用 PascalCase
class user_manager {}                   // 类名应该使用 PascalCase
class UserManager {}                    // 类名应该使用 PascalCase

const userInstance = new User();        // 类实例名应该使用 camelCase
const UserInstance = new User();       // 类实例名应该使用 camelCase

function GetUser() {}                   // 函数名应该使用 camelCase
function get_user() {}                  // 函数名应该使用 camelCase

function process(userName) {}          // 参数名应该使用 snake_case
const maxRetry = 5;                     // 变量名应该使用 snake_case
const defaultTimeout = 1000;           // 常量名应该使用 UPPER_SNAKE_CASE

// ✅ 正确的命名示例
class User {}
class DbConn {}

const userInstance = new User();
const dbConn = new DbConn();

function getUser() {}
function process() {}

function process(user_name) {}
const max_retry = 5;
const DEFAULT_TIMEOUT = 1000;

单词长度验证

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

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

禁止的冗余词汇

插件会自动检测并禁止使用以下冗余词汇:

类名禁止词: manager, handler, processor, controller, service, provider, factory, builder, adapter, decorator, proxy, facade, mediator, observer, strategy, command, visitor, iterator, template, flyweight, memento, interpreter, model, view, route, router, component, widget, panel, dialog, window, form, field, property, entity

函数名禁止词: data, result, output, input, param, params, parameter, parameters, value, values, item, items, process, processor, provider, builder, adapter, decorator, proxy, facade, mediator, observer, strategy, command, visitor, iterator, template, flyweight, memento, interpreter, temp, tmp, temporary, cached, buffered, idx, counter, with

变量名禁止词: object, array, map, set, collection, container, instance, data, item, items, element, elements, entry, entries, temp, tmp, temporary, cached, buffer, buffered, input, output, result, destination, index, idx, counter, length, total, sum, pointer, reference, ref, handle, handler, entity, column, property, attribute, manager, processor, controller, service, middleware, component, provider

命名推荐功能

插件包含智能命名推荐系统,建议使用更短的替代名称,同时保持语义不变。

核心原则

核心原则是**"缩短命名而不改变语义"**。推荐系统:

  • 推荐更短的单词,同时保持相同含义
  • 避免会改变功能的概念性变化
  • 确保推荐词始终比原词短
  • 保留编程特定术语和概念差异

可用推荐

插件为常见编程操作提供推荐:

| 原词 | 推荐词 | 描述 | | ------------ | -------- | ---------- | | calculate | calc | 数学运算 | | generate | gen | 数据生成 | | initialize | init | 初始化操作 | | execute | exec | 命令执行 | | process | run | 数据处理 | | retrieve | load | 数据加载 | | persist | save | 数据存储 | | compare | cmp | 比较操作 | | duplicate | copy | 数据复制 | | transfer | move | 数据移动 | | convert | to | 类型转换 | | verify | check | 验证检查 | | construct | create | 对象创建 | | handle | run | 事件处理 |

示例

// ❌ 原词(较长名称)
function calculateTotal() {}
function generateUserData() {}
function initializeSystem() {}
function executeCommand() {}
function processData() {}

// ✅ 推荐词(较短名称)
function calcTotal() {}
function genUserData() {}
function initSystem() {}
function execCommand() {}
function runData() {}

带推荐的错误消息

启用推荐功能后,ESLint将建议替代名称:

# ESLint输出示例
function calculateTotal() {}
# ^ 建议使用'calc'替代'calculate'以获得更短的命名

开发

项目结构

mm_eslint/
├── index.js          # 主插件文件
├── config.js         # 配置管理
├── detector.js       # 命名检测器
├── validator.js      # 验证器
├── corrector.js      # 命名修正器
├── tip.js            # 提示信息
├── util.js           # 工具函数
├── handler.js        # 规则处理器
├── fix.js            # 自动修复功能
├── package.json      # npm配置
├── eslint.config.js  # ESLint配置示例
├── README.md         # 中文说明文档
├── README_EN.md      # 英文说明文档
├── LICENSE           # 许可证
└── tests/            # 测试文件
    ├── success/      # 正确示例
    ├── error/        # 错误示例
    └── scence/       # 场景测试

运行测试

# 运行单元测试
npm test

# 运行ESLint检查
npm run lint

发布说明

npm发布

插件已发布到npm,可以通过以下命令安装:

npm install mm_eslint --save-dev

版本管理

项目使用语义化版本控制(Semantic Versioning):

  • 主版本号:不兼容的API修改
  • 次版本号:向下兼容的功能性新增
  • 修订号:向下兼容的问题修正

发布流程

  1. 更新版本号:npm version patch|minor|major
  2. 运行测试:npm test
  3. 代码检查:npm run lint
  4. 发布到npm:npm publish

许可证

ISC License

贡献

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

更新日志

v1.4.4

  • 更新插件名称和规则前缀为 mm_eslint
  • 优化模块结构和文件组织
  • 增强测试覆盖率和错误处理
  • 改进文档和示例

v1.4.3

  • 优化模块结构和文件组织
  • 增强测试覆盖率和错误处理
  • 改进文档和示例

v1.2.0

  • 模块化重构版,职责分离
  • 增强配置管理
  • 改进命名检测算法

v1.1.0

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

v1.0.0

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