Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 9d3bbb9

Browse files
authored
Merge pull request #2 from sj-distributor/1-init-eslint-plugin-react
ok,now.
2 parents 0f82b3f + 966ae85 commit 9d3bbb9

File tree

16 files changed

+5015
-1
lines changed

16 files changed

+5015
-1
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# For more information about the properties used in
2+
# this file, please see the EditorConfig documentation:
3+
# https://editorconfig.org/
4+
5+
root = true
6+
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
indent_size = 2
11+
indent_style = space
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.eslintrc.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
3+
module.exports = {
4+
root: true,
5+
env: {
6+
es2022: true,
7+
},
8+
parserOptions: {
9+
ecmaVersion: "latest",
10+
sourceType: "module",
11+
},
12+
plugins: ["unicorn"],
13+
extends: [
14+
"eslint:recommended",
15+
"plugin:eslint-plugin/recommended",
16+
"plugin:node/recommended",
17+
"plugin:prettier/recommended",
18+
],
19+
rules: {
20+
"node/no-unpublished-require": [
21+
"error",
22+
{
23+
allowModules: ["requireindex"],
24+
},
25+
],
26+
},
27+
overrides: [
28+
{
29+
files: ["tests/**/*.js"],
30+
env: { mocha: true },
31+
},
32+
],
33+
};

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
env:
5+
CI: true
6+
VERSION: ${{ github.event.pull_request.number }}
7+
8+
jobs:
9+
publish:
10+
name: Install and publish
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 14.x
20+
21+
- name: Restore yarn cache
22+
id: yarn-cache
23+
uses: actions/cache@v2
24+
with:
25+
path: "**/node_modules"
26+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
27+
28+
- name: Install dependencies
29+
if: steps.yarn-cache.outputs.cache-hit != 'true'
30+
run: |
31+
yarn install --cwd example --frozen-lockfile
32+
yarn install --frozen-lockfile
33+
34+
- name: Check eslint
35+
run: yarn lint
36+
37+
- name: Check test
38+
run: yarn test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"dbaeumer.vscode-eslint",
5+
"EditorConfig.EditorConfig"
6+
]
7+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.quickSuggestions": {
3+
"strings": true
4+
},
5+
"editor.formatOnSave": true,
6+
"editor.codeActionsOnSave": {
7+
"source.fixAll.eslint": true
8+
},
9+
"editor.defaultFormatter": "esbenp.prettier-vscode",
10+
"prettier.requireConfig": true
11+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Simon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README-ZH.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# 👨‍💻 @sj-distributor/eslint-plugin-react
2+
3+
[![Npm Version](https://img.shields.io/npm/v/npm.svg)](https://www.npmjs.com/package/@sj-distributor/eslint-plugin-react)
4+
[![MIT License](https://img.shields.io/npm/l/react-native-tab-view.svg?style=flat-square)](https://www.npmjs.com/package/@sj-distributor/eslint-plugin-react)
5+
[![downloads](https://img.shields.io/npm/dm/eslint-config-standard.svg)](https://www.npmjs.com/package/@sj-distributor/eslint-plugin-react)
6+
[![Ci](https://github.com/sj-distributor/eslint-plugin-react/actions/workflows/ci.yml/badge.svg)](https://github.com/sj-distributor/eslint-plugin-react/actions/workflows/ci.yml)
7+
8+
用于 react native 的 ESLint 预置
9+
10+
## 安装
11+
12+
你首先需要安装 [ESLint](https://eslint.org/):
13+
14+
```sh
15+
yarn add eslint
16+
17+
or
18+
19+
npm i eslint --save-dev
20+
```
21+
22+
接下来,安装 `@sj-distributor/eslint-plugin-react`:
23+
24+
```sh
25+
26+
yarn add @sj-distributor/eslint-plugin-react
27+
28+
or
29+
30+
npm install @sj-distributor/eslint-plugin-react --save-dev
31+
```
32+
33+
## 使用
34+
35+
Add `eslint-plugin-react` to the extends section of your `.eslintrc` configuration file:
36+
37+
```json
38+
{
39+
"extends": ["plugin:@sj-distributor/eslint-plugin-react/recommended"]
40+
}
41+
```
42+
43+
## 使用了哪些规则?
44+
45+
- [eslint](https://eslint.org/)
46+
- [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier#readme)
47+
- [eslint-plugin-eslint-plugin](https://github.com/eslint-community/eslint-plugin-eslint-plugin#readme)
48+
- [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import)
49+
- [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node#readme)
50+
- [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier#readme)
51+
- [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react)
52+
- [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks)
53+
- [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort#readme)

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
# eslint-plugin-react
1+
# 👨‍💻 @sj-distributor/eslint-plugin-react
2+
3+
[![Npm Version](https://img.shields.io/npm/v/npm.svg)](https://www.npmjs.com/package/@sj-distributor/eslint-plugin-react)
4+
[![MIT License](https://img.shields.io/npm/l/react-native-tab-view.svg?style=flat-square)](https://www.npmjs.com/package/@sj-distributor/eslint-plugin-react)
5+
[![downloads](https://img.shields.io/npm/dm/eslint-config-standard.svg)](https://www.npmjs.com/package/@sj-distributor/eslint-plugin-react)
6+
[![Ci](https://github.com/sj-distributor/eslint-plugin-react/actions/workflows/ci.yml/badge.svg)](https://github.com/sj-distributor/eslint-plugin-react/actions/workflows/ci.yml)
7+
8+
ESLint presets for react
9+
10+
### [中文文档](https://github.com/sj-distributor/eslint-plugin-react/blob/master/README-ZH.md)
11+
12+
## Installation
13+
14+
You'll first need to install [ESLint](https://eslint.org/):
15+
16+
```sh
17+
yarn add eslint
18+
19+
or
20+
21+
npm i eslint --save-dev
22+
```
23+
24+
Next, install `@sj-distributor/eslint-plugin-react`:
25+
26+
```sh
27+
28+
yarn add @sj-distributor/eslint-plugin-react
29+
30+
or
31+
32+
npm install @sj-distributor/eslint-plugin-react --save-dev
33+
```
34+
35+
## Usage
36+
37+
Add `eslint-plugin-react` to the extends section of your `.eslintrc` configuration file:
38+
39+
```json
40+
{
41+
"extends": ["plugin:@sj-distributor/eslint-plugin-react/recommended"]
42+
}
43+
```
44+
45+
## What rules are used?
46+
47+
- [eslint](https://eslint.org/)
48+
- [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier#readme)
49+
- [eslint-plugin-eslint-plugin](https://github.com/eslint-community/eslint-plugin-eslint-plugin#readme)
50+
- [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import)
51+
- [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node#readme)
52+
- [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier#readme)
53+
- [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react)
54+
- [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks)
55+
- [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort#readme)

configs/.eslintrc.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module.exports = {
2+
root: true,
3+
extends: [
4+
"eslint:recommended",
5+
"plugin:prettier/recommended",
6+
"plugin:react-hooks/recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
],
9+
parser: "@typescript-eslint/parser",
10+
plugins: ["react", "simple-import-sort", "unicorn", "import"],
11+
env: {
12+
es2022: true,
13+
browser: true,
14+
node: true,
15+
},
16+
parserOptions: {
17+
sourceType: "module",
18+
ecmaVersion: "latest",
19+
ecmaFeatures: {
20+
jsx: true,
21+
},
22+
},
23+
rules: {
24+
camelcase: "error", // 要求变量命名使用驼峰式
25+
"spaced-comment": "error", // 要求强制执行注释 // 或 /* 开始后的间距的一致性
26+
"import/extensions": 0, // (关闭) .js 解析为模块并检查 exports 的文件扩展名列表,如果是React 或者使用 TypeScript 将要去共享配置 settings 添加修改
27+
"import/no-unresolved": 0, // (关闭) 导入的模块可以解析为本地文件系统上的模块
28+
"no-duplicate-imports": "error", // 要求每个模块只能有一个 imports,相同的内容可以在各自的 imports 上看到导入的内容
29+
"react/react-in-jsx-scope": 0, // (关闭) 使用 jsx 时不允许缺少 React 的引入
30+
"simple-import-sort/imports": "error", // imports 排序
31+
"simple-import-sort/exports": "error", // exports 排序
32+
// 强制文件名大小写样式
33+
"unicorn/filename-case": [
34+
"error",
35+
{
36+
cases: {
37+
kebabCase: true, // 是否支持横杠 (-) 命名
38+
camelCase: false, // 是否支持小驼峰命名
39+
snakeCase: false, // 是否支持 (_) 下划线命名
40+
pascalCase: false, // 是否支持大坨峰命名
41+
},
42+
},
43+
],
44+
// Hooks 有依赖项的话强制要求补充依赖项
45+
"react-hooks/rules-of-hooks": "error",
46+
"react-hooks/exhaustive-deps": ["error"],
47+
// 要求或不允许在给定的2种语句之间有空行
48+
"padding-line-between-statements": [
49+
"error",
50+
{ blankLine: "always", prev: "*", next: "return" }, // 要求 return 语句之前要有空行
51+
{
52+
blankLine: "always",
53+
prev: ["function", "const", "var", "let"], // 指定语法糖语句之间要有空行
54+
next: "*",
55+
},
56+
],
57+
},
58+
// 共享配置,提供给每一个将被执行的规则
59+
settings: {
60+
"import/resolver": {
61+
node: {
62+
extensions: [".js", ".jsx", ".ts", ".tsx"],
63+
},
64+
},
65+
react: {
66+
version: "detect", // ‘detect’ 会自动选择你所安装的 React 版本
67+
},
68+
},
69+
};

0 commit comments

Comments
 (0)