Skip to content

Commit

Permalink
chore: add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Jan 12, 2025
1 parent dabddcd commit 0921e52
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 2 deletions.
149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<div align="center">
<img src="https://github.com/user-attachments/assets/4e0a0b81-7814-48b1-ae3d-9ce0511e0e9c" width="120" height="120" alt="logo" />
<h1>@configurajs/eslint</h1>
<p>A simple eslint flat configuration</p>
<p>
<span>English</span> |
<a href="https://github.com/configurajs/eslint/blob/main/README.zh-CN.md">中文介绍</a>
</p>
<p>
<img src="https://img.shields.io/github/package-json/v/configurajs/eslint" alt="version">
<img src="https://img.shields.io/github/stars/configurajs/eslint" alt="stars">
<img src="https://img.shields.io/github/license/configurajs/eslint" alt="license">
</p>
</div>

---

## Features

- 📦 &nbsp; Support javascript presets
- 📦 &nbsp; Support typescript presets
- 📦 &nbsp; Support vue(2 and 3) presets
- 📦 &nbsp; Support react presets
- 📦 &nbsp; Support jsx presets
- 📦 &nbsp; Support eslint comments presets
- 📦 &nbsp; Support overrides eslint config

## Quick Start

### Installation

```shell
# npm
npm i @configurajs/eslint -D
# yarn
yarn add @configurajs/eslint -D
# pnpm
pnpm add @configurajs/eslint -D
```

### Usage

```js
// eslint.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig()
```

OR

```js
// eslint.config.js
const { defineConfig } = require('@configurajs/eslint')

module.exports = defineConfig()
```

### Switch Framework Presets

Switching framework presets requires manual setup.

#### Vue2

```js
// eslint.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig({
vue: { version: 2 },
})
```

#### React

```js
// eslint.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig({
vue: false,
react: true,
})
```

### Options

```js
// prettier.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig({ ... })
```

```ts
export interface DefineConfigOptions {
/**
* Enable TypeScript support
* @default true
*/
ts?: boolean
/**
* Enable JSX support
* @default true
*/
jsx?: boolean
/**
* Enable Vue support, version 3 by default
* @default true
*/
vue?: boolean | { version: 2 | 3 }
/**
* Enable React support
* @default false
*/
react?: boolean
/**
* Enable eslint comments support
* @default true
*/
comments?: boolean
/**
* Custom rules
*/
rules?: Linter.RulesRecord
/**
* Ignore files
*/
ignores?: string[]
/**
* Override eslint configs
*/
overrides?: Linter.Config[]
}
```

## Contributors

<a href="https://github.com/configurajs/eslint/graphs/contributors">
<img src="https://contrib.rocks/image?repo=configurajs/eslint" />
</a>

## ChangeLog

[ChangeLog](CHANGELOG.md)

## License

[MIT](LICENSE)
149 changes: 149 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<div align="center">
<img src="https://github.com/user-attachments/assets/4e0a0b81-7814-48b1-ae3d-9ce0511e0e9c" width="120" height="120" alt="logo" />
<h1>@configurajs/eslint</h1>
<p>A simple eslint flat configuration</p>
<p>
<span>中文</span> |
<a href="https://github.com/configurajs/eslint/blob/main/README.md">English</a>
</p>
<p>
<img src="https://img.shields.io/github/package-json/v/configurajs/eslint" alt="version">
<img src="https://img.shields.io/github/stars/configurajs/eslint" alt="stars">
<img src="https://img.shields.io/github/license/configurajs/eslint" alt="license">
</p>
</div>

---

## 功能

- 📦 &nbsp; 支持 javascript 预设
- 📦 &nbsp; 支持 typescript 预设
- 📦 &nbsp; 支持 vue(2 和 3) 预设
- 📦 &nbsp; 支持 react 预设
- 📦 &nbsp; 支持 jsx 预设
- 📦 &nbsp; 支持 eslint comments 预设
- 📦 &nbsp; 支持覆盖 eslint 配置

## 快速开始

### 安装

```shell
# npm
npm i @configurajs/eslint -D
# yarn
yarn add @configurajs/eslint -D
# pnpm
pnpm add @configurajs/eslint -D
```

### 用法

```js
// eslint.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig()
```


```js
// eslint.config.js
const { defineConfig } = require('@configurajs/eslint')

module.exports = defineConfig()
```

### 切换框架预设

切换框架预设需要通过手动设置。

#### Vue2

```js
// eslint.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig({
vue: { version: 2 },
})
```

#### React

```js
// eslint.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig({
vue: false,
react: true,
})
```

### 更多选项

```js
// prettier.config.js
import { defineConfig } from '@configurajs/eslint'

export default defineConfig({ ... })
```

```ts
export interface DefineConfigOptions {
/**
* 启用 TypeScript 支持
* @default true
*/
ts?: boolean
/**
* 启用 JSX 支持
* @default true
*/
jsx?: boolean
/**
* 启用 Vue 支持,默认为版本 3
* @default true
*/
vue?: boolean | { version: 2 | 3 }
/**
* 启用 React 支持
* @default false
*/
react?: boolean
/**
* 启用 eslint 注释支持
* @default true
*/
comments?: boolean
/**
* 自定义规则
*/
rules?: Linter.RulesRecord
/**
* 忽略文件
*/
ignores?: string[]
/**
* 覆盖 eslint 配置
*/
overrides?: Linter.Config[]
}
```

## 贡献者

<a href="https://github.com/configurajs/eslint/graphs/contributors">
<img src="https://contrib.rocks/image?repo=configurajs/eslint" />
</a>

## 更新日志

[ChangeLog](CHANGELOG.md)

## 协议

[MIT](LICENSE)
4 changes: 2 additions & 2 deletions src/configs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CreateVueConfigOptions {
export function createVueConfig(options: CreateVueConfigOptions): Linter.Config[] {
const { ts, version } = options

const rules: Partial<Linter.RulesRecord> =
const versionSpecificRules: Partial<Linter.RulesRecord> =
version === 2
? {
'vue/comment-directive': 'error',
Expand Down Expand Up @@ -152,7 +152,7 @@ export function createVueConfig(options: CreateVueConfigOptions): Linter.Config[
'vue/no-lone-template': 'warn',
'vue/no-multiple-slot-args': 'warn',
'vue/this-in-template': 'warn',
...rules,
...versionSpecificRules,
},
},
]
Expand Down
29 changes: 29 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,42 @@ import { createRulesConfig } from './configs/rules'
export type DefineConfigOptionsVue = Partial<Pick<CreateVueConfigOptions, 'version'>>

export interface DefineConfigOptions {
/**
* Enable TypeScript support
* @default true
*/
ts?: boolean
/**
* Enable JSX support
* @default true
*/
jsx?: boolean
/**
* Enable Vue support, version 3 by default
* @default true
*/
vue?: boolean | DefineConfigOptionsVue
/**
* Enable React support
* @default false
*/
react?: boolean
/**
* Enable eslint comments support
* @default true
*/
comments?: boolean
/**
* Custom rules
*/
rules?: Linter.RulesRecord
/**
* Ignore files
*/
ignores?: string[]
/**
* Override eslint configs
*/
overrides?: Linter.Config[]
}

Expand Down

0 comments on commit 0921e52

Please sign in to comment.