# @baiducloud/eslint-config-react

<p align="center">
    <a href="https://nodejs.org/en/about/releases/">
      <img src="https://img.shields.io/badge/node-%3E%3D%2016.0.0-green" alt="node compatility">
    </a>
    <a href="https://www.npmjs.com/package/eslint/">
      <img src="https://img.shields.io/npm/v/eslint.svg" alt="node compatility">
    </a>
</p>

Console 控制台前端业务使用的 ESlint 配置，基于[v8.21.0](https://eslint.org/blog/2022/08/eslint-v8.21.0-released/)引入的新版配置实现，后续的 v9 版本中`.eslintrc*`将不再支持。

✔ 基于[@ecomfe/eslint-config/react](https://github.com/ecomfe/eslint-config/tree/master/react)扩展

## 开发

### 添加 Plugin

如果需要添加一个插件，那么这个插件应该被指定为 `peerDependency`，这是因为插件将在最终用户的项目中被加载，所以最终用户需要自己安装他们需要的插件。之后，在项目的`rules`目录下创建`demo-rule.js`规则文件，将需要实现的规则加入到文件中，例如：

```js
// demo-rule.js
export default {
  quotes: [2, 'double']
};
```

然后在`index.js`中扩展：

```js
import DemoPlugin from 'eslint-plugin-demo';
import DemoRule from './rules/demo-rule';

{
  plugins: {
    "demo-plugin": DemoPlugin
  }
  rules: {
    ...DemoRule
  }
}
```

### 添加 Shared Config

如果需要添加一个外部的可共享配置，则需要在`package.json`中将这些包指定为依赖项，然后在`index.js`的数组中添加一个`FlatConfig`

### 调试

在当前项目中执行`npm link`，然后在目标项目中执行`npm link @baiducloud/eslint-config-react`，这样就可以在目标项目中调试当前项目。

## 安装

`npm i -D @baiducloud/eslint-config-react`

> 如果使用的 npm 版本小于 7.0，需要手动安装 peerDependency`npm i -D eslint`

## 使用

建议使用新版的 flat config system，即：`eslint.config.js`是唯一的配置文件名称，`.eslintrc*`等格式的名称，以及 json、yaml 格式的配置文件都将不再支持。

在[ESLint 配置](https://eslint.org/docs/latest/use/configure/configuration-files-new)扩展：

```ts
export default [
  {
    rules: {
      'semi': 'error',
      'prefer-const': 'error'
    }
  }
];
```
