@enonic/eslint-config

中文文档
3.0.0发布于 2026/10/09MITCommonJS近 30 天下载 2548

ESLint rules for JavaScript and TypeScript by Enonic.

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Configuration
  4. XP and Browser
  5. Vanilla JavaScript
  6. TypeScript
  7. License

Enonic ESLint Config

Install

  1. Install the latest version of the config:
npm install --save-dev @enonic/eslint-config
  1. Install the correct versions of each package, which are listed by the command:
npm info "@enonic/eslint-config@latest" peerDependencies

If you DON'T need to lint TypeScript, you should skip this step (see the vanilla configuration).

Make sure you intall the same version of @typescript-eslint/eslint-plugin and @typescript-eslint/parser packages.

Usage

.eslintrc.json

{
    "extends": "@enonic/eslint-config",
    "overrides": [
        {
            "files": ["*.ts", "*.tsx"],
            "parserOptions": {
                "project": "./tsconfig.json"
            }
        }
    ]
}

Some of the rules require parserServices to be generated, therefore project property must be explicitly set. Take a note, that TypeScript configuration is isolated by the *.ts/*.tsx scope.

Configuration

Aside from @enonic/eslint-config, this package contains four more configurations:

Standalone

  • @enonic/eslint-config/vanilla should replace default configuration in JavaScript-only projects.
  • @enonic/eslint-config/typescript should replace default configuration in TypeScript-only projects.

Helpers

  • @enonic/eslint-config/browser adds additional configuration for linting browser files (assets).
  • @enonic/eslint-config/xp adds XP global variables and allows to lint files that will be used by XP.

Helpers must be combined with the default, vanilla, or typescript configuration.

XP and Browser

Your project may contain both server-side and client-side files. In this case, it might be reasonable to use overrides, to prevent specific config to be applied for improper files:

.eslintrc.json

{
    "extends": "@enonic/eslint-config",
    "overrides": [
+       {
+           "files": [
+               "src/main/resources/assets/*.js",
+               "src/main/resources/assets/*.ts"
+           ],
+           "extends": "@enonic/eslint-config/browser"
+       },
+       {
+           "files": [
+               "src/main/resources/lib/*.js",
+               "src/main/resources/lib/*.ts"
+           ],
+           "extends": "@enonic/eslint-config/xp"
+       },
        {
            "files": ["*.ts", "*.tsx"],
            "parserOptions": {
                "project": "./tsconfig.json"
            }
        }
    ]
}

Vanilla JavaScript

The default configuration will lint both TS and JS files. If your project doesn't use TypeScript, then @enonic/eslint-config/vanilla configuration can be used instead. project property must not be specified. No other TS-related peer dependencies must be installed either.

.eslintrc.json

{
-   "extends": "@enonic/eslint-config",
+   "extends": "@enonic/eslint-config/vanilla",
    "overrides": [
-       {
-           "files": ["*.ts", "*.tsx"],
-           "parserOptions": {
-               "project": "./tsconfig.json"
-           }
-       }
+       {
+           "files": ["src/main/resources/assets/*.js"],
+           "extends": "@enonic/eslint-config/browser"
+       },
+       {
+           "files": ["src/main/resources/lib/*.js"],
+           "extends": "@enonic/eslint-config/xp"
+       }
    ]
}

TypeScript

When using the TypeScript configuration instead of the default one, project property must be moved to the parserOptions under the config's root. This configuration should be prefered over the default one, if you lint TypeScript files only. It simplifies the configuration file a bit.

.eslintrc.json

{
-   "extends": "@enonic/eslint-config",
+   "extends": "@enonic/eslint-config/typescript",
+   "parserOptions": {
+       "project": "./tsconfig.json"
+   }
    "overrides": [
-       {
-           "files": ["*.ts", "*.tsx"],
-           "parserOptions": {
-               "project": "./tsconfig.json"
-           }
-       }
+       {
+           "files": ["src/main/resources/assets/*.ts"],
+           "extends": "@enonic/eslint-config/browser"
+       },
+       {
+           "files": ["src/main/resources/lib/*.ts"],
+           "extends": "@enonic/eslint-config/xp"
+       }
    ]
}

License

MIT © Enonic

版本与发布记录

@enonic/eslint-config 共发布 13 个版本,首次发布于 2022/05/23;过去 12 个月发布了 4 个版本。

版本发布日期距今
3.0.0latest2026/10/091 个月前
2.3.02026/05/076 个月前
2.2.12025/12/1710 个月前
2.2.02025/12/1710 个月前
2.1.02025/08/111.3 年前
2.0.12024/11/192 年前

关于 @enonic/eslint-config 的常见问题

@enonic/eslint-config 是什么?

ESLint rules for JavaScript and TypeScript by Enonic.

如何安装 @enonic/eslint-config?

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

@enonic/eslint-config 支持 TypeScript 吗?

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

@enonic/eslint-config 支持 ESM 还是 CommonJS?

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

@enonic/eslint-config 可以商用吗?

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

@enonic/eslint-config 的下载量有多少?

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

@enonic/eslint-config 还在维护吗?

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