@bam.tech/eslint-plugin

中文文档
9.2.0发布于 2026/05/12MITCommonJS构建来源已验证近 30 天下载 1.3万

eslint plugin for bam projects

原始使用文档
文档目录8 节
  1. Quick Setup
  2. Setting up the plugin on a monorepo
  3. Handling files ignored by TypeScript
  4. ⚠️ React version
  5. Shareable configurations
  6. Eslint rules
  7. How to customize?
  8. Contribute

ESLint plugin by BAM

This project is an ESLint plugin that gathers all the rules, plugins and parsers that should be used in any new react-native BAM project.

The list of rules and configuration details can be found here.

Quick Setup

Install the plugin and its peer dependencies:

yarn add @bam.tech/eslint-plugin --dev
npx install-peerdeps @bam.tech/eslint-plugin --dev --yarn

Legacy Config (ESLint 8.x and below)

Then update your .eslintrc config file:

// .eslintrc
{
  "extends": "plugin:@bam.tech/recommended",
  "overrides": [
    {
      "files": ["*.test.tsx", "*.test.ts"],
      "extends": "plugin:@bam.tech/tests"
    }
  ]
}

Flat Config

  • Install the plugin: yarn add -D @bam.tech/eslint-plugin
  • Create an eslint.config.js file in your project root:
const pluginBam = require("@bam.tech/eslint-plugin");

module.exports = [
  ...pluginBam.configs.recommended,
  ...pluginBam.configs.a11y,
  ...pluginBam.configs.import,
  ...pluginBam.configs.tests,
  {
    rules: {
      "@bam.tech/require-named-effect": "error",
    },
  },
];

Setting up the plugin on a monorepo

Update your .vscode/settings.json by adding the directories of apps using the plugin:

// .vscode/settings.json
{
  ...
  "eslint.workingDirectories": [
    "apps/yourFirstApp",
    "apps/yourSecondApp"
    ]
}

Handling files ignored by TypeScript

The plugin default behavior is to use TypeScript configuration to lint all TypeScript files. However, in your project, there may be files you've chosen to ignore with TypeScript. It's advisable to also disable ESLint checking for these files. To achieve this, add the files you want to ignore with ESLint in the overrides section of your eslintrc.js. Below is an example illustrating this. The configuration for mock files is overridden: the TypeScript parser is removed, and the behavior of the @typescript-eslint/return-await rule is modified.

overrides: [
  {
    files: ["mocks/**/*"],
    parserOptions: {
      project: null,
    },
    rules: {
      "@typescript-eslint/return-await": "off",
    },
  },
];

⚠️ React version

With the introduction of React 18, it's no longer necessary to import React in your JSX files. The ESLint plugin is configured for React version 18 and above, so you won't encounter any errors. However, TypeScript will generate an error if it isn't configured correctly. To resolve this, simply add "jsx": "react-native" to your tsconfig.json file.

If your project is using a version of React that's below 18, iyou should upgrade to a newer version of React. If upgrading isn't an option, here's the situation: importing React in your JSX files remains mandatory, but ESLint won't flag any errors, even though it should. This is due to the plugin configuration; the recommended configuration extends the plugin react/jsx-runtime, which disables the following rules:

  • 'react/jsx-uses-react': "error"
  • 'react/react-in-jsx-scope': "error"

These rules are crucial as they trigger an error when React is not in scope. Therefore, you'll need to include them in the rules section of your .eslintrc.js file to ensure an error is flagged whenever someone omits the import for React.

Remember, the recommended solution is to upgrade to a newer version of React. This advice should only be disregarded in exceptional circumstances where upgrading React is not feasible.

Shareable configurations

This plugin exports multiple configurations that can be used in your .eslintrc config file:

NameDescription
@bam.tech/recommendedThe recommended config for all projects
@bam.tech/testsThe recommended config for test files. By default this applies to every file: put it in an overrides to filter on your test files.
@bam.tech/a11y[beta] Eslint config to check for accessibility. Still in beta to not break existing projects, but will be merged into the recommended config in the future.

These configs need some peer dependencies. You can list them with:

npm info "@bam.tech/esling-plugin" peerDependencies

If you use npm >= 5 you can automatically install them by running:

npx install-peerdeps @bam.tech/eslint-config -D

Eslint rules

This plugin exports some custom rules that you can optionally use in your project:

💼 Configurations enabled in.
✅ Set in the recommended configuration.
🧪 Set in the tests configuration.
🔧 Automatically fixable by the --fix CLI option.

NameDescription💼🔧
await-user-eventEnforces awaiting userEvent calls🧪🔧
no-different-displaynameEnforce component displayName to match with component name✅🔧
no-inline-styleDetect inline styles in JSX✅
prefer-user-eventEnforces usage of userEvent over fireEvent in tests.🧪🔧
require-named-effectEnforces the use of named functions inside a useEffect✅

To use a rule, just declare it in your .eslintrc:

// .eslintrc
{
  "plugins": ["@bam.tech"],
  "rules": {
    "@bam.tech/require-named-effect": "error"
  }
}

Tip: if your config is already extended from a @bam.tech config, you don't need to declare the plugin.

How to customize?

You can still customize your ESLint config by adding other configurations, plugins and rules to your .eslintrc config file.

Contribute

If you find a useful rule that you feel every project at BAM should use, feel free to contribute.

版本与发布记录

@bam.tech/eslint-plugin 共发布 31 个版本,首次发布于 2023/07/04;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.2.0latest2026/05/125 个月前
9.1.02026/02/248 个月前
9.0.52026/01/299 个月前
9.0.42026/01/279 个月前
8.0.02025/10/311 年前
7.1.12025/10/311 年前

关于 @bam.tech/eslint-plugin 的常见问题

@bam.tech/eslint-plugin 是什么?

eslint plugin for bam projects

如何安装 @bam.tech/eslint-plugin?

在项目目录运行 npm install @bam.tech/eslint-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(^9.37.0)、globals(^16.0.0)、prettier(^3.6.2)、typescript-eslint(^8.19.1)、eslint-plugin-jest(^29.0.1)、eslint-plugin-react(^7.37.5)、eslint-plugin-import(^2.32.0)、eslint-config-prettier(^10.1.8)、eslint-plugin-prettier(^5.2.1)、eslint-plugin-react-hooks(^7.0.0)、eslint-plugin-react-native(^5.0.0)、eslint-plugin-eslint-plugin(^6.4.0)、eslint-plugin-unused-imports(^4.2.0)、eslint-plugin-testing-library(^7.13.1)、eslint-plugin-react-native-a11y(^3.5.1)、@typescript-eslint/eslint-plugin(^8.46.0)、eslint-plugin-simple-import-sort(^12.1.1)、eslint-import-resolver-typescript(^4.4.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bam.tech/eslint-plugin 支持 TypeScript 吗?

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

@bam.tech/eslint-plugin 支持 ESM 还是 CommonJS?

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

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

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

@bam.tech/eslint-plugin 可以商用吗?

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

@bam.tech/eslint-plugin 的下载量有多少?

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

@bam.tech/eslint-plugin 还在维护吗?

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