@hootool/eslint-config-react-native
v0.1.0
Published
React Native 专用 ESLint 规则配置 (ESLint v9 Flat Config, 继承 base)
Maintainers
Readme
@hootool/eslint-config-react-native
React Native 专用 ESLint 规则配置,继承 @hootool/eslint-config,基于 ESLint v9 Flat Config。
特性
在 base 基础上叠加:
eslint-plugin-import-x的 react-native preset:支持.ios.js/.android.js/.web.js平台扩展名解析- RN 全局变量:
__DEV__、fetch、React、global等 - 关闭与 RN 环境冲突的规则(如
no-console)
安装
pnpm add -D @hootool/eslint-config-react-native eslint使用
// eslint.config.js
import rnConfig from '@hootool/eslint-config-react-native';
export default rnConfig;如需自定义:
// eslint.config.js
import rnConfig, { defineConfig } from '@hootool/eslint-config-react-native';
export default defineConfig(
...rnConfig,
{
rules: {
'no-alert': 'off',
},
},
);
defineConfig与globals由 base 包 re-export,可直接从本包导入。
与 base 的差异
| 规则 | base | react-native |
|------|------|--------------|
| no-console | warn(允许 warn/error) | off(RN 调试依赖 console) |
| no-unused-expressions | warn | off |
| 全局变量 | browser + node | node + RN 专属(__DEV__ 等) |
| import 解析 | 标准扩展名 | 含平台扩展名(.ios.js 等) |
配置块结构
共 11 个配置块:base 9 块 + import-x react-native preset + RN 环境配置。
