Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Eslint config init, based on airbnb-base #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!.eslintrc.js
!.prettierrc.js

node_modules/
.DS_Store
yarn.lock
yarn-error.log
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
root: true,
extends: ['./typescript.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
};
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.DS_Store

package-lock.json
yarn.lock
yarn-error.log
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.DS_Store
yarn.lock
yarn-error.log

*ignore
39 changes: 39 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
// 一行最多 120 字符
printWidth: 120,
// 使用 2 个空格缩进
tabWidth: 2,
// 不使用缩进符,而使用空格
useTabs: false,
// 行尾需要有分号
semi: true,
// 使用单引号
singleQuote: true,
// 对象的 key 仅在必要时用引号
quoteProps: 'as-needed',
// jsx 不使用单引号,而使用双引号
jsxSingleQuote: false,
// 末尾需要有逗号
trailingComma: 'all',
// 大括号内的首尾需要空格
bracketSpacing: true,
// jsx 标签的反尖括号需要换行
jsxBracketSameLine: false,
// 箭头函数,只有一个参数的时候,也需要括号
arrowParens: 'always',
// 每个文件格式化的范围是文件的全部内容
rangeStart: 0,
rangeEnd: Infinity,
// 不需要写文件开头的 @prettier
requirePragma: false,
// 不需要自动在文件开头插入 @prettier
insertPragma: false,
// 使用默认的折行标准
proseWrap: 'preserve',
// 根据显示样式决定 html 要不要折行
htmlWhitespaceSensitivity: 'css',
// vue 文件中的 script 和 style 内不用缩进
vueIndentScriptAndStyle: false,
// 换行符使用 lf
endOfLine: 'lf',
};
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"files.eol": "\n",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"typescript",
"typescriptreact"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,118 @@
# eslint-config-tdesign
ESLint config for TDesign

>Tips: 规则有优先级,注意 `extends` 中的顺序
>1. 如果 `extends` 配置的是一个数组,那么最终会将所有规则项进行合并,出现冲突的时候,后面的会覆盖前面的。
>2. 通过 `rules` 单独配置的规则,优先级高于 `extends` 。


## Base Usage
### Installation
```sh
npm i eslint eslint-config-airbnb-base eslint-plugin-tdesign --save-dev
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign"
]
}
```

## Miniprogram Usage
### Installation
```sh
npm i eslint eslint-config-airbnb-base eslint-config-prettier eslint-plugin-import eslint-plugin-tdesign --save-dev
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign",
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
"tdesign/miniprogram"
]
}
```

## TypeScript Usage
### Installation
```sh
npm install eslint typescript eslint-config-airbnb-base @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tdesign --save-dev
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign",
"tdesign/typescript"
]
}
```

## Vue Usage
### Installation
```sh
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
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign",
"tdesign/vue"
]
}
```
## Vue-next Usage
### Installation
```sh
npm i eslint eslint-config-airbnb-base eslint-config-prettier vue-eslint-parser eslint-plugin-vue eslint-plugin-tdesign --save-dev
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign",
"tdesign/vue-next"
]
}
```

## React Usage
### Installation
```sh
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
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign",
"tdesign/react"
]
}
```

## TypeScript React Usage
### Installation
```sh
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
```
### Use
```json
// .eslintrc.js
{
"extends": [
"tdesign",
"tdesign/typescript",
"tdesign/react",
]
}
```
24 changes: 24 additions & 0 deletions base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const javascriptRule = require('./rules/javascript');

module.exports = {
root: true,
extends: ['eslint-config-airbnb-base'],
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
allowImportExportEverywhere: true,
ecmaFeatures: {
impliedStrict: true,
jsx: true,
},
},
env: {
browser: true,
node: true,
es6: true,
jest: true,
},
rules: {
...javascriptRule,
},
};
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['./base.js'],
};
31 changes: 31 additions & 0 deletions miniprogram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
extends: ['plugin:prettier/recommended'],
plugins: ['import'],
globals: {
require: true,
Page: true,
wx: true,
App: true,
getApp: true,
getCurrentPages: true,
Component: true,
getRegExp: true,
Behavior: true,
},
rules: {},
overrides: [
{
files: ['script/**'],
rules: {
// node 环境下支持 require
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['example/**'],
rules: {
'no-console': 0,
},
},
],
};
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "eslint-config-tdesign",
"version": "0.0.0",
anlyyao marked this conversation as resolved.
Show resolved Hide resolved
"description": "ESLint config for TDesign",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin",
"eslintconfig",
"tdesign",
"vue",
"react",
"typescript"
],
"author": "none",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"dependencies": {},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"@vue/eslint-config-typescript": "^10.0.0",
"eslint": "^7.0.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-eslint-plugin": "^4.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-lodash": "^7.4.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-vue": "^8.7.1",
"prettier": "^2.6.2",
"react": "^18.1.0",
"typescript": "^4.6.3",
"vue-eslint-parser": "^8.3.0"
},
"peerDependencies": {},
"license": "MIT"
}
19 changes: 19 additions & 0 deletions react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const reactRule = require('./rules/react');

module.exports = {
extends: [
'prettier', // eslint-config-prettier 处理冲突
'plugin:react/recommended',
'plugin:import/typescript',
],
plugins: ['react-hooks', 'lodash'],
settings: {
react: {
pragma: 'React',
version: 'detect',
},
},
rules: {
...reactRule,
},
};
Loading