Skip to content

Commit 2a02bc0

Browse files
committed
feat: Eslint config init, based on airbnb-base
1 parent 4d022bd commit 2a02bc0

19 files changed

+680
-0
lines changed

.eslintignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!.eslintrc.js
2+
!.prettierrc.js
3+
4+
node_modules/
5+
.DS_Store
6+
yarn.lock
7+
yarn-error.log

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['./typescript.js'],
4+
rules: {
5+
'@typescript-eslint/no-var-requires': 'off',
6+
},
7+
};

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.DS_Store
3+
4+
package-lock.json
5+
yarn.lock
6+
yarn-error.log

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
.DS_Store
3+
yarn.lock
4+
yarn-error.log
5+
6+
*ignore

.prettierrc.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
// 一行最多 120 字符
3+
printWidth: 120,
4+
// 使用 2 个空格缩进
5+
tabWidth: 2,
6+
// 不使用缩进符,而使用空格
7+
useTabs: false,
8+
// 行尾需要有分号
9+
semi: true,
10+
// 使用单引号
11+
singleQuote: true,
12+
// 对象的 key 仅在必要时用引号
13+
quoteProps: 'as-needed',
14+
// jsx 不使用单引号,而使用双引号
15+
jsxSingleQuote: false,
16+
// 末尾需要有逗号
17+
trailingComma: 'all',
18+
// 大括号内的首尾需要空格
19+
bracketSpacing: true,
20+
// jsx 标签的反尖括号需要换行
21+
jsxBracketSameLine: false,
22+
// 箭头函数,只有一个参数的时候,也需要括号
23+
arrowParens: 'always',
24+
// 每个文件格式化的范围是文件的全部内容
25+
rangeStart: 0,
26+
rangeEnd: Infinity,
27+
// 不需要写文件开头的 @prettier
28+
requirePragma: false,
29+
// 不需要自动在文件开头插入 @prettier
30+
insertPragma: false,
31+
// 使用默认的折行标准
32+
proseWrap: 'preserve',
33+
// 根据显示样式决定 html 要不要折行
34+
htmlWhitespaceSensitivity: 'css',
35+
// vue 文件中的 script 和 style 内不用缩进
36+
vueIndentScriptAndStyle: false,
37+
// 换行符使用 lf
38+
endOfLine: 'lf',
39+
};

.vscode/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"files.eol": "\n",
3+
"editor.tabSize": 2,
4+
"editor.formatOnSave": true,
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"eslint.validate": [
7+
"javascript",
8+
"javascriptreact",
9+
"vue",
10+
"typescript",
11+
"typescriptreact"
12+
],
13+
"editor.codeActionsOnSave": {
14+
"source.fixAll.eslint": true
15+
},
16+
"typescript.tsdk": "node_modules/typescript/lib"
17+
}

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
11
# eslint-config-tdesign
22
ESLint config for TDesign
3+
4+
>Tips: 规则有优先级,注意 `extends` 中的顺序
5+
>1. 如果 `extends` 配置的是一个数组,那么最终会将所有规则项进行合并,出现冲突的时候,后面的会覆盖前面的。
6+
>2. 通过 `rules` 单独配置的规则,优先级高于 `extends`
7+
8+
9+
## Base Usage
10+
### Installation
11+
```sh
12+
npm i eslint eslint-config-airbnb-base eslint-plugin-tdesign --save-dev
13+
```
14+
### Use
15+
```json
16+
// .eslintrc.js
17+
{
18+
"extends": [
19+
"tdesign"
20+
]
21+
}
22+
```
23+
24+
## Miniprogram Usage
25+
### Installation
26+
```sh
27+
npm i eslint eslint-config-airbnb-base eslint-config-prettier eslint-plugin-import eslint-plugin-tdesign --save-dev
28+
```
29+
### Use
30+
```json
31+
// .eslintrc.js
32+
{
33+
"extends": [
34+
"tdesign",
35+
"tdesign/miniprogram"
36+
]
37+
}
38+
```
39+
40+
## TypeScript Usage
41+
### Installation
42+
```sh
43+
npm install eslint typescript eslint-config-airbnb-base @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tdesign --save-dev
44+
```
45+
### Use
46+
```json
47+
// .eslintrc.js
48+
{
49+
"extends": [
50+
"tdesign",
51+
"tdesign/typescript"
52+
]
53+
}
54+
```
55+
56+
## Vue Usage
57+
### Installation
58+
```sh
59+
npm i eslint eslint-config-airbnb-base eslint-config-prettier vue-eslint-parser eslint-plugin-vue @vue/eslint-config-typescript eslint-plugin-tdesign --save-dev
60+
```
61+
### Use
62+
```json
63+
// .eslintrc.js
64+
{
65+
"extends": [
66+
"tdesign",
67+
"tdesign/vue"
68+
]
69+
}
70+
```
71+
## Vue-next Usage
72+
### Installation
73+
```sh
74+
npm i eslint eslint-config-airbnb-base eslint-config-prettier vue-eslint-parser eslint-plugin-vue eslint-plugin-tdesign --save-dev
75+
```
76+
### Use
77+
```json
78+
// .eslintrc.js
79+
{
80+
"extends": [
81+
"tdesign",
82+
"tdesign/vue-next"
83+
]
84+
}
85+
```
86+
87+
## React Usage
88+
### Installation
89+
```sh
90+
npm i eslint prettier eslint-config-airbnb-base eslint-config-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-lodash eslint-plugin-tdesign --save-dev
91+
```
92+
### Use
93+
```json
94+
// .eslintrc.js
95+
{
96+
"extends": [
97+
"tdesign",
98+
"tdesign/react"
99+
]
100+
}
101+
```
102+
103+
## TypeScript React Usage
104+
### Installation
105+
```sh
106+
npm install eslint typescript eslint-config-airbnb-base eslint-config-prettier @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-plugin-tdesign --save-dev
107+
```
108+
### Use
109+
```json
110+
// .eslintrc.js
111+
{
112+
"extends": [
113+
"tdesign",
114+
"tdesign/typescript",
115+
"tdesign/react",
116+
]
117+
}
118+
```

base.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const javascriptRule = require('./rules/javascript');
2+
3+
module.exports = {
4+
root: true,
5+
extends: ['eslint-config-airbnb-base'],
6+
parserOptions: {
7+
ecmaVersion: 2019,
8+
sourceType: 'module',
9+
allowImportExportEverywhere: true,
10+
ecmaFeatures: {
11+
impliedStrict: true,
12+
jsx: true,
13+
},
14+
},
15+
env: {
16+
browser: true,
17+
node: true,
18+
es6: true,
19+
jest: true,
20+
},
21+
rules: {
22+
...javascriptRule,
23+
},
24+
};

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['./base.js'],
3+
};

miniprogram.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
module.exports = {
2+
extends: ['plugin:prettier/recommended'],
3+
plugins: ['import'],
4+
globals: {
5+
require: true,
6+
Page: true,
7+
wx: true,
8+
App: true,
9+
getApp: true,
10+
getCurrentPages: true,
11+
Component: true,
12+
getRegExp: true,
13+
Behavior: true,
14+
},
15+
rules: {},
16+
overrides: [
17+
{
18+
files: ['script/**'],
19+
rules: {
20+
// node 环境下支持 require
21+
'@typescript-eslint/no-require-imports': 'off',
22+
},
23+
},
24+
{
25+
files: ['example/**'],
26+
rules: {
27+
'no-console': 0,
28+
},
29+
},
30+
],
31+
};
32+
33+
// 配置小程序内全局函数,避免报错
34+
// const globals = {
35+
// require: true,
36+
// Page: true,
37+
// wx: true,
38+
// App: true,
39+
// getApp: true,
40+
// getCurrentPages: true,
41+
// Component: true,
42+
// getRegExp: true,
43+
// Behavior: true,
44+
// };
45+
46+
// module.exports = {
47+
// parser: '@typescript-eslint/parser',
48+
// parserOptions: {
49+
// ecmaVersion: 2018,
50+
// sourceType: 'module',
51+
// ecmaFeatures: {
52+
// impliedStrict: true,
53+
// },
54+
// },
55+
// env: {
56+
// browser: true,
57+
// node: true,
58+
// es6: true,
59+
// jest: true,
60+
// },
61+
// // 启用默认核心规则
62+
// extends: ['eslint-config-airbnb-base', 'eslint-config-prettier'],
63+
// plugins: ['@typescript-eslint', 'prettier', 'import'],
64+
// // add your custom rules here
65+
// rules: {
66+
// // 非开发模式禁用debugger
67+
// 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
68+
// // 允许调用首字母大写的函数时没有 new 操作符
69+
// 'new-cap': 'off',
70+
// // 在工具库中允许变量以下划线开头
71+
// 'no-underscore-dangle': 'off',
72+
// // 在工具库中允许参数重新赋值
73+
// 'no-param-reassign': 'off',
74+
// 'number-leading-zero': 'off',
75+
// // 在类属性和方法上关闭需要显式的可访问性修饰符
76+
// '@typescript-eslint/explicit-member-accessibility': 'off',
77+
// eqeqeq: [
78+
// 'error',
79+
// 'always',
80+
// {
81+
// null: 'ignore',
82+
// },
83+
// ],
84+
// 'import/no-unresolved': 0,
85+
// 'import/no-named-as-default': 0,
86+
// 'import/extensions': 0,
87+
// 'import/export': 0,
88+
// 'import/no-cycle': 0,
89+
// 'import/no-extraneous-dependencies': [
90+
// 'error',
91+
// {
92+
// devDependencies: true,
93+
// },
94+
// ],
95+
// 'import/no-dynamic-require': 0,
96+
// 'object-shorthand': 0,
97+
// 'no-shadow': 0,
98+
// 'no-unused-expressions': 0,
99+
// 'no-unused-vars': 0,
100+
// '@typescript-eslint/no-unused-vars': 2,
101+
// 'consistent-return': 0,
102+
// 'no-return-assign': 0,
103+
// 'func-names': 0,
104+
// 'class-methods-use-this': 0,
105+
// 'no-console': [
106+
// 2,
107+
// {
108+
// allow: ['warn', 'error'],
109+
// },
110+
// ],
111+
// 'no-undef': 0,
112+
// 'no-proto': 0,
113+
// },
114+
// // globals,
115+
// overrides: [
116+
// {
117+
// files: ['script/**'],
118+
// rules: {
119+
// // node 环境下支持 require
120+
// '@typescript-eslint/no-require-imports': 'off',
121+
// },
122+
// },
123+
// {
124+
// files: ['example/**'],
125+
// rules: {
126+
// 'no-console': 0,
127+
// },
128+
// },
129+
// ],
130+
// };

0 commit comments

Comments
 (0)