forked from TDesignOteam/eslint-config-tdesign
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Eslint config init, based on airbnb-base
- Loading branch information
Showing
19 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/ | ||
.DS_Store | ||
yarn.lock | ||
yarn-error.log | ||
|
||
*ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
### 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", | ||
"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", | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['./base.js'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
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, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
// 配置小程序内全局函数,避免报错 | ||
// const globals = { | ||
// require: true, | ||
// Page: true, | ||
// wx: true, | ||
// App: true, | ||
// getApp: true, | ||
// getCurrentPages: true, | ||
// Component: true, | ||
// getRegExp: true, | ||
// Behavior: true, | ||
// }; | ||
|
||
// module.exports = { | ||
// parser: '@typescript-eslint/parser', | ||
// parserOptions: { | ||
// ecmaVersion: 2018, | ||
// sourceType: 'module', | ||
// ecmaFeatures: { | ||
// impliedStrict: true, | ||
// }, | ||
// }, | ||
// env: { | ||
// browser: true, | ||
// node: true, | ||
// es6: true, | ||
// jest: true, | ||
// }, | ||
// // 启用默认核心规则 | ||
// extends: ['eslint-config-airbnb-base', 'eslint-config-prettier'], | ||
// plugins: ['@typescript-eslint', 'prettier', 'import'], | ||
// // add your custom rules here | ||
// rules: { | ||
// // 非开发模式禁用debugger | ||
// 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn', | ||
// // 允许调用首字母大写的函数时没有 new 操作符 | ||
// 'new-cap': 'off', | ||
// // 在工具库中允许变量以下划线开头 | ||
// 'no-underscore-dangle': 'off', | ||
// // 在工具库中允许参数重新赋值 | ||
// 'no-param-reassign': 'off', | ||
// 'number-leading-zero': 'off', | ||
// // 在类属性和方法上关闭需要显式的可访问性修饰符 | ||
// '@typescript-eslint/explicit-member-accessibility': 'off', | ||
// eqeqeq: [ | ||
// 'error', | ||
// 'always', | ||
// { | ||
// null: 'ignore', | ||
// }, | ||
// ], | ||
// 'import/no-unresolved': 0, | ||
// 'import/no-named-as-default': 0, | ||
// 'import/extensions': 0, | ||
// 'import/export': 0, | ||
// 'import/no-cycle': 0, | ||
// 'import/no-extraneous-dependencies': [ | ||
// 'error', | ||
// { | ||
// devDependencies: true, | ||
// }, | ||
// ], | ||
// 'import/no-dynamic-require': 0, | ||
// 'object-shorthand': 0, | ||
// 'no-shadow': 0, | ||
// 'no-unused-expressions': 0, | ||
// 'no-unused-vars': 0, | ||
// '@typescript-eslint/no-unused-vars': 2, | ||
// 'consistent-return': 0, | ||
// 'no-return-assign': 0, | ||
// 'func-names': 0, | ||
// 'class-methods-use-this': 0, | ||
// 'no-console': [ | ||
// 2, | ||
// { | ||
// allow: ['warn', 'error'], | ||
// }, | ||
// ], | ||
// 'no-undef': 0, | ||
// 'no-proto': 0, | ||
// }, | ||
// // globals, | ||
// overrides: [ | ||
// { | ||
// files: ['script/**'], | ||
// rules: { | ||
// // node 环境下支持 require | ||
// '@typescript-eslint/no-require-imports': 'off', | ||
// }, | ||
// }, | ||
// { | ||
// files: ['example/**'], | ||
// rules: { | ||
// 'no-console': 0, | ||
// }, | ||
// }, | ||
// ], | ||
// }; |
Oops, something went wrong.