@encoura/eslint-config

中文文档
4.0.3发布于 2026/11/04MITCommonJS近 30 天下载 4877

Encoura's preferred configs for TypeScript, Prettier, ESLint, CommitLint, and MarkdownLint.

原始使用文档
文档目录11 节
  1. Getting Started
  2. Configure CommitLint
  3. Configure ESLint
  4. Breaking Changes In v4
  5. Configure MarkdownLint
  6. Configure Prettier
  7. Configure TypeScript
  8. Dependency Upgrade Notes
  9. Local Development
  10. npm Scripts
  11. Release Process

ESLint Config

Encoura's preferred configs for TypeScript, Prettier, ESLint, CommitLint, and MarkdownLint.

Getting Started

Install this package, ESLint, husky, and lint-staged as dev dependencies:

npm install --save-dev @encoura/eslint-config eslint@^10 husky lint-staged

Configure husky by adding the following to your package.json file:

...
"scripts": {
  ...
  "prepare": "husky",
  ...
},
...

Configure CommitLint

To configure CommitLint, create a commitlint.config.js file in the root of your project that contains the following:

module.exports = require('@encoura/eslint-config/commitlint.config');

This will allow CommitLint to discover the configuration this repository provides from within your node_modules folder.

By default the Encoura commitlint expects a commit message in the following format:

[XXX-###]: Subject where XXX-### is a work item id, e.g., WEB-1

The commit message may also be in the form of git's standard merge commit format.

Configure ESLint

To configure ESLint, add the following to your eslint.config.js and package.json files. This package supports ESLint 10's flat config system. This repository develops and validates the config on Node 24.

Five upstream packages still declare peer ranges that exclude ESLint 10: Airbnb, Airbnb Base, Import, React, and JSX accessibility. Their original implementations and rule names are retained. The build bundles those packages and their locked production dependencies into the published artifact. It widens only their ESLint peer metadata to include v10 and Airbnb's React Hooks peer metadata to include v7.

These are package-local compatibility patches, not upstream declarations of support. The existing @eslint/compat adapters handle legacy rule APIs. Consumers need no peer overrides or --legacy-peer-deps. Tests install the packed artifact with strict peers, compare complete rule inventories, and verify that bundled implementation files match the installed originals.

Bundled dependencies are fixed by this package's lockfile. Their updates require a new package build and release. Use npm ci before release builds. Remove each compatibility patch when its upstream package supports these peer versions.

const createConfig = require('@encoura/eslint-config');

module.exports = createConfig({
  nextRootDir: __dirname,
  resolverProject: ['tsconfig.json'],
  tsconfigRootDir: __dirname,
});

For back-end (Nest.js) projects:

const createConfig = require('@encoura/eslint-config/nest');

module.exports = createConfig({
  resolverProject: ['tsconfig.json'],
  tsconfigRootDir: __dirname,
});
...
"lint-staged": {
  ...
  "*.{js,jsx,ts,tsx}": "eslint",
  ...
},
...

Breaking Changes In v4

  • ESLint config consumers must use ESLint 10 flat config. Legacy .eslintrc extends: ['@encoura/eslint-config'] and extends: ['@encoura/eslint-config/nest'] usage is no longer supported. Create an eslint.config.js file and call the exported config factory instead.
  • Install eslint@^10 directly in consuming projects. This package declares ESLint 10 as a peer so the project-level eslint CLI resolves to the expected major version.
  • The published jest.config.js export and Jest-related dependencies were removed. Projects that imported @encoura/eslint-config/jest.config should own their Jest or Vitest config locally.
  • Jest-specific test linting is no longer enabled by this shared ESLint config. Test files still receive the shared TypeScript/React overrides, but Vitest projects no longer inherit Jest rules.
  • eslint-plugin-disable is no longer bundled. The shared config did not enable any disable/* rules; projects that used that package transitively should add their own dependency.

Configure MarkdownLint

To configure MarkdownLint, add the following to your package.json file. This will allow MarkdownLint to discover the configuration this repository provides from within your node_modules folder, and will check your *.md files for infractions every time you create a new commit:

...
"lint-staged": {
  ...
  "*.{md}": "markdownlint --config node_modules/@encoura/eslint-config/markdownlint.config.json",
  ...
},
...

Configure Prettier

To configure prettier, create a .prettierrc.js file in the root of your project that contains the following:

module.exports = require('@encoura/eslint-config/prettier.config');

This will allow Prettier to discover the configuration this repository provides from within your node_modules folder.

Next, add the following to your package.json file so that prettier will check your files for infractions every time you create a new commit:

...
"lint-staged": {
  ...
  "*.{js,jsx,json,md,ts,tsx}": [
    "prettier --write",
    "git add"
  ]
  ...
},
...

Configure TypeScript

To configure TypeScript, add the following to your tsconfig.json file. This will allow TypeScript to discover the configuration this repository provides from within your node_modules folder:

...
"extends": "node_modules/@encoura/eslint-config/tsconfig.json",
...

Dependency Upgrade Notes

See UPGRADE-NOTES.md for security fixes, tooling compatibility changes, consumer migration steps, and validation commands.

Local Development

npm Scripts

There are several npm scripts at your disposal during local development. Here are some of the more important ones:

ScriptDescription
npm testRun all validation checks.
npm run test:lint:jsLint JavaScript files with the shared ESLint config.
npm run test:lint:tsLint TypeScript files with the shared ESLint config.
npm run test:lint:mdLint Markdown files with the shared MarkdownLint config.
npm run test:prettierCheck formatting with Prettier.
npm run test:tsconfigValidate the shared TypeScript config.
npm run test:unitRun unit tests for the exported config factories.

Release Process

When your code changes are ready, it's time to publish a new patch, minor, or major release. Maintainers typically squash pull requests when merging, so the PR title becomes the squash commit title and is the source of truth for patch and minor release detection.

  1. Make a PR (or mark your draft PR as ready for review).

  2. Choose a public-safe PR title that lets Semantic Release know if this should yield a new patch, minor, or major release:

    • If you expect the merging of your PR to result in a new patch release, start your PR title with fix:.
    • If you expect the merging of your PR to result in a new minor release, start your PR title with feat:.
    • If you expect the merging of your PR to result in a new major release, see #3 below for details.
    • If you expect the merging of your PR to skip the creation of a new release, you can start your PR title with build: (for build changes), chore: (for basic maintenance), docs: (for documentation updates), or simply do not use any of the above keyword prefixes.
  3. If the pull request should create a new major version release, the string BREAKING CHANGE: must be included in at least one commit message's footer (see docs) — Semantic Release's commit analyzer does not use the PR title in determining major releases.

    You can either manually add BREAKING CHANGE: to the commit footer after pressing "Merge Pull Request"/"Squash and Merge" in your PR (in the "optional extended description" field). Alternatively, if you're merging the PR by creating a new merge commit, ensure that at least one of the source commits' messages has BREAKING CHANGE: in its footer. Note that to accomplish this you may need to commit with the --no-verify flag to bypass commitlint.

  4. Once your PR is merged, Semantic Release will pick it up and initiate the automated release process. If it detects that it should create a release (based on the above), it will. Otherwise, it won't!

版本与发布记录

@encoura/eslint-config 共发布 21 个版本,首次发布于 2023/09/16;过去 12 个月发布了 5 个版本。

版本发布日期距今
4.0.3latest2026/11/0410 天前
4.0.22026/09/241 个月前
4.0.12026/06/115 个月前
4.0.02026/06/105 个月前
3.0.12026/01/139 个月前
3.0.02025/07/011.4 年前

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

@encoura/eslint-config 是什么?

Encoura's preferred configs for TypeScript, Prettier, ESLint, CommitLint, and MarkdownLint.

如何安装 @encoura/eslint-config?

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

@encoura/eslint-config 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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