@automattic/eslint-plugin-wpvip

中文文档
2.0.1发布于 2026/10/06GPL-2.0+CommonJS构建来源已验证近 30 天下载 1.1万

ESLint plugin for internal WordPress VIP projects

原始使用文档
文档目录11 节
  1. Installation
  2. ESLint 10
  3. Upgrading to 2.0
  4. Contributing
  5. Configuration
  6. Recommended config
  7. Prettier
  8. Editorconfig
  9. CLI
  10. JSDoc
  11. "Weak" configs

WordPress VIP ESLint plugin

This is an ESLint plugin to provide WordPress VIP's (internal) JavaScript and TypeScript coding standards. It is inspired by and borrows from @wordpress/eslint-plugin.

Installation

Install eslint and @automattic/eslint-plugin-wpvip to your project.

npm install --save-dev eslint @automattic/eslint-plugin-wpvip

ESLint 9 (^9.39.1) and ESLint 10 are supported.

Optional integrations are auto-detected when your project also installs typescript, jest, react, or prettier. These packages are declared as optional peer dependencies so consumers can opt in to the stacks they actually use.

ESLint 10

eslint-plugin-jsx-a11y and eslint-plugin-react work with ESLint 10 (this plugin shims eslint-plugin-react with @eslint/compat), but they have not yet published releases that declare ESLint 10 in their peer dependencies. To avoid ERESOLVE errors with npm, add these overrides to your project's package.json. $eslint refers to your project's own eslint entry, so eslint must be listed directly in devDependencies (or dependencies):

"overrides": {
    "eslint-plugin-jsx-a11y": { "eslint": "$eslint" },
    "eslint-plugin-react": { "eslint": "$eslint" }
}

Upgrading to 2.0

2.0 adds ESLint 10 support and contains these breaking changes:

  • eslint-plugin-import is replaced by eslint-plugin-import-x. It is registered under the import namespace, so rule IDs such as import/order and eslint-disable comments are unchanged. However:
    • Settings now use the import-x/ prefix. import/* settings (import/resolver, import/internal-regex, import/core-modules, …) are ignored; rename them, e.g. import/resolver → import-x/resolver.
    • Do not register eslint-plugin-import under import yourself; ESLint will throw Cannot redefine plugin "import".
    • import/enforce-node-protocol-usage does not exist in eslint-plugin-import-x; remove it from your config.
    • eslint-plugin-import is no longer installed with this package. If your config requires it, add it to your own devDependencies.
  • JavaScript files are parsed with ESLint's default parser (espree) instead of @babel/eslint-parser. Your project's Babel config is no longer applied, so syntax that only Babel understands (e.g. Flow or legacy decorators) is not supported, and parserOptions.babelOptions / requireConfigFile are ignored. The ECMAScript version follows ESLint's default (latest), so new built-in globals (e.g. SuppressedError, Iterator) are recognized.
  • Deprecated core formatting rules moved to @stylistic/eslint-plugin. ESLint is removing its formatting rules, so the formatting, javascript and react configs now use @stylistic/* rules configured with the same options (e.g. indent → @stylistic/indent, func-call-spacing → @stylistic/function-call-spacing). Rename any overrides or eslint-disable comments for these rules; overriding the old core names no longer has any effect. no-new-symbol is replaced by no-new-native-nonconstructor.
    • Results are not always identical: @stylistic fixes bugs in the frozen core rules. Notably, @stylistic/indent now checks lines whose indentation mixes tabs and spaces (core indent skipped them), such as a closing } / ) / ] indented with tabs plus two spaces, and indents chained assignments (a = b = c) differently. This only matters if the formatting rules are active, i.e. you don't use the prettier config, which turns them off.
    • This package registers @stylistic/eslint-plugin under @stylistic. If your config also registers it, make sure npm resolves the same copy (a compatible version range), or ESLint will throw Cannot redefine plugin "@stylistic".
  • The jsdoc config no longer enables jsdoc/newline-after-description, which was removed from eslint-plugin-jsdoc and made the config fail to load.
  • ESLint ^9.39.1 or ^10.0.0 is required (previously ^9.7.0).
  • Node.js ^22.22.2 || >=24.15.0 is required, including with ESLint 9 (Node.js 20 is end-of-life). eslint-plugin-jsdoc 65 requires these versions; @stylistic/eslint-plugin is ESM-only and is loaded with require(), which needs Node's built-in require(esm) support, and @eslint/compat (used to support eslint-plugin-react on ESLint 10) needs Node.js 20.19+ / 22.13+.

Contributing

See CONTRIBUTING.md for details on development, testing, publishing, etc.

Configuration

Create an eslint.config.cjs file. The .cjs extension makes Node.js treat it as CommonJS even if your package.json has "type": "module". The examples in this README use this file:

const wpvip = require( '@automattic/eslint-plugin-wpvip' );

module.exports = [ ...wpvip.configs.recommended ];

And that's it! It works automatically with most JavaScript and TypeScript projects.

The typescript, testing, react, and prettier parts of recommended are loaded only when the corresponding package is installed. If you need those optional configs resolved up front rather than when recommended is loaded, require init first. It uses the same detection as recommended, so optional integrations whose package is not installed are still skipped:

require( '@automattic/eslint-plugin-wpvip/init' );

Code editors that are configured to work with ESLint will automatically pick up the rules and flag any errors or warnings.

If your project uses only JavaScript, you do not need to install the optional peers. If you use the modular typescript, testing, react, or prettier configs directly, install the corresponding package in your project first.

To skip files or paths, add a config object with ignores (for example { ignores: [ 'dist/**' ] }) to the array.

Package scripts can be useful to run linting and formatting commands automatically. Here are some suggested scripts for your project's package.json—only copy the ones that are useful to you. The cmd: scripts help you compose commands without repeating verbose CLI arguments.

{
    "scripts": {
        "cmd:format": "prettier '**/*.(js|json|jsx|md|ts|tsx|yml|yaml)'",
        "cmd:lint": "eslint",
        "format": "npm run cmd:format -- --write",
        "format:check": "npm run cmd:format -- --check",
        "lint": "npm run cmd:lint .",
        "lint:fix": "npm run cmd:lint . -- --fix",
        "lint:ignore-warnings": "npm run cmd:lint . -- --quiet"
    }
}

Note: ESLint reads ignore patterns from the ignores key in eslint.config.cjs; to reuse .gitignore, see includeIgnoreFile. Prettier automatically ignores files listed in .prettierignore or you can target .gitignore using --ignore-path.

The "recommended" config includes rules for JavaScript, TypeScript, Jest, and React, including rules related to formatting and white space. It is intended to be strict! Opinionated defaults keep our codebases consistent and reduce the friction we experience when context-switching between projects.

Of course, this recommended config may not be ideal for every project, so feel free to "build your own" using the available modular configs. The recommended config is equivalent to:

const wpvip = require( '@automattic/eslint-plugin-wpvip' );

module.exports = [
    ...wpvip.configs.javascript,
    ...wpvip.configs.formatting,
    ...wpvip.configs.typescript, // when "typescript" is installed
    ...wpvip.configs.testing, // when "jest" is installed
    ...wpvip.configs.react, // when "react" is installed
    ...wpvip.configs.prettier, // when "prettier" is installed
];

Note that the order of configs can matter, since they can contain overrides. It is particularly important to add the prettier config last.

Prettier

Install WP Prettier v3.x to benefit from additional formatting rules:

npm i --save-dev --save-exact "prettier@npm:[email protected]"

This repo also provides a Prettier config, which you can use with the following .prettierrc:

"@automattic/eslint-plugin-wpvip/prettierrc"

For maximum benefit, see Prettier's documentation on enabling format-on-save in your editor. This enables you to concentrate on coding while Prettier handles formatting.

Editorconfig

Editorconfig provides additional formatting rules and works well with Prettier. Copy the .editorconfig file from this repo into your project.

CLI

The cli config allows certain behaviors that are usually against best practice but are useful in a codebase that produces a CLI tool:

module.exports = [ ...wpvip.configs.recommended, ...wpvip.configs.cli ];

If your project is not a CLI tool but spawns child processes occasionally, you probably don't need this config. Instead, disable those rules only where necessary and include an explanation:

// Running a fixed, trusted command.
// eslint-disable-next-line security/detect-child-process
const { execSync } = require( 'child_process' );

Note that console.log is still forbidden (see here for an explanation). If you're writing one-off Node scripts, you can disable the rule per file:

/* eslint-disable no-console */

JSDoc

JSDoc is considered optional, especially compared to better alternatives like TypeScript and OpenAPI documentation. If you want to enforce the use of JSDoc, use the jsdoc config:

module.exports = [ ...wpvip.configs.recommended, ...wpvip.configs.jsdoc ];

Note that rules that require @param and @return types are relaxed in TypeScript files.

"Weak" configs

This plugin provides a few so-called "weak" configs for legacy codebases that are working to transition to stronger standards. These configs downgrade select rules from the recommended config to warnings. Warnings will still be visible in code editors and other outputs but will not fail continous integration workflows.

These configs are intended for temporary use and should not be used long-term. We also do not recommend the use of tools like eslines to ignore errors or warnings. While the intention is to prevent large-scale changes and transition slowly to stronger standards, the effect is usually that the transition stalls and eventually stops completely.

Three "weak" configs are available: weak-javascript, weak-typescript, and weak-testing. While pull requests on this project are always welcome, please carefully consider whether adding rules to these configs is truly necessary. Ideally, we work to remove rules from these configs until they are no longer needed.

版本与发布记录

@automattic/eslint-plugin-wpvip 共发布 47 个版本,首次发布于 2022/04/30;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.1latest2026/10/061 个月前
2.0.02026/10/021 个月前
1.3.12026/09/131 个月前
1.3.02026/06/055 个月前
1.2.12026/04/206 个月前
1.2.02026/02/228 个月前

其他发布通道:beta → 0.1.1-0,test → 0.4.13,next → 0.5.1。

关于 @automattic/eslint-plugin-wpvip 的常见问题

@automattic/eslint-plugin-wpvip 是什么?

ESLint plugin for internal WordPress VIP projects

如何安装 @automattic/eslint-plugin-wpvip?

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

@automattic/eslint-plugin-wpvip 支持 TypeScript 吗?

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

@automattic/eslint-plugin-wpvip 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@automattic/eslint-plugin-wpvip 需要什么版本的 Node.js?

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

@automattic/eslint-plugin-wpvip 可以商用吗?

@automattic/eslint-plugin-wpvip 使用 GPL-2.0+ 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@automattic/eslint-plugin-wpvip 的下载量有多少?

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

@automattic/eslint-plugin-wpvip 还在维护吗?

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