Skip to content

Commit

Permalink
feat: update eslint-config-sh
Browse files Browse the repository at this point in the history
  • Loading branch information
BestDingSheng committed Jan 25, 2022
1 parent 52eac90 commit f3ee9c6
Show file tree
Hide file tree
Showing 14 changed files with 584 additions and 41 deletions.
72 changes: 36 additions & 36 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
module.exports = {
parser: "babel-eslint",
parserOptions: {
sourceType: "module", // 设置为 "script" (默认) 或 "module"(ES6)。
ecmaFeatures: {
// 这是个对象,表示你想使用的额外的语言特性:
jsx: true, // 启用 JSX
globalReturn: true,
impliedStrict: true,
ecmaVersion: 6,
},
},
env: {
browser: true,
node: true,
},
extends: [
"airbnb",
"eslint:recommended",
"plugin:import/errors",
"plugin:jsx-a11y/recommended",
"plugin:prettier/recommended",
"plugin:react/recommended",
],
plugins: [
// 'react-hooks',
],
globals: {
// 允许在代码中使用全局变量
location: true,
setTimeout: true,
},
rules: {
"no-unused-vars": 1,
},
};
// module.exports = {
// parser: "babel-eslint",
// parserOptions: {
// sourceType: "module", // 设置为 "script" (默认) 或 "module"(ES6)。
// ecmaFeatures: {
// // 这是个对象,表示你想使用的额外的语言特性:
// jsx: true, // 启用 JSX
// globalReturn: true,
// impliedStrict: true,
// ecmaVersion: 6,
// },
// },
// env: {
// browser: true,
// node: true,
// },
// extends: [
// "airbnb",
// "eslint:recommended",
// "plugin:import/errors",
// "plugin:jsx-a11y/recommended",
// "plugin:prettier/recommended",
// "plugin:react/recommended",
// ],
// plugins: [
// // 'react-hooks',
// ],
// globals: {
// // 允许在代码中使用全局变量
// location: true,
// setTimeout: true,
// },
// rules: {
// "no-unused-vars": 1,
// },
// };
80 changes: 78 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ npm install -save eslint-config-sh
npx install-peerdeps --dev eslint-config-sh
```

2 在项目跟目录下添加 .eslintrc.js
<!-- 2 在项目跟目录下添加 .eslintrc.js
```js
module.exports = {
Expand All @@ -33,4 +33,80 @@ module.exports = {
{
"tabWidth": 2
}
```
``` -->

## 使用

### JavaScrip

```bash
npm install --save-dev eslint babel-eslint eslint-plugin-babel eslint-plugin-import eslint-config-sh

```

```json
{
"root": true,
"extends": "sh"
}
```

### Typescript

```
npm install --save-dev eslint typescript eslint-plugin-babel eslint-plugin-import @typescript-eslint/eslint-plugin eslint-config-sh
```

```json
{
"root": true,
"extends": "sh/typescript"
}
```

### React

```
npm install --save-dev eslint babel-eslint eslint-plugin-babel eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-config-sh
```

```json
{
"root": true,
"extends": "sh/react"
}
```


### Vue

```
npm install --save-dev eslint babel-eslint eslint-plugin-babel eslint-plugin-import eslint-plugin-vue eslint-config-sh
```


```json
{
"root": true,
"extends": "sh/vue"
}
```

### 项目依赖

- "babel-eslint": "^10.1.0",
- "eslint": "^7.23.0",
- "eslint-config-airbnb": "^18.2.1",
- "eslint-config-prettier": "^8.1.0",
- "eslint-plugin-import": "^2.22.1",
- "eslint-plugin-jsx": "^0.1.0",
- "eslint-plugin-jsx-a11y": "^6.4.1",
- "eslint-plugin-prettier": "^3.3.1",
- "eslint-plugin-react": "^7.23.1",
- "eslint-plugin-react-hooks": "^4.2.0",
- @typescript-eslint/eslint-plugin
- "@typescript-eslint/parser": "^4.9.0",
- eslint-plugin-vue
- typescript
2 changes: 1 addition & 1 deletion __test__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const a = 10;
// const a = 10;
20 changes: 20 additions & 0 deletions configs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
parserOptions: {
ecmaFeatures: {
globalReturn: true,
impliedStrict: true,
},
requireConfigFile: false,
allowImportExportEverywhere: false,
},
env: {
browser: true,
},
globals: {
__CLIENT__: true,
__SERVER__: true,
__DEVELOPMENT__: true,
__DEBUG__: true,
__DEVTOOLS__: true,
},
};
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const eslintrc = require("./.eslintrc.js");
// const eslintrc = require("./.eslintrc.js");

module.exports = eslintrc;
// module.exports = eslintrc;

module.exports = {
extends: [
"./configs/base",
"eslint-config-airbnb-base",
"./rules/es",
"./rules/import",
].map(require.resolve),
parser: "babel-eslint",
};
11 changes: 11 additions & 0 deletions react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
extends: [
"./configs/base",
"eslint-config-airbnb",
"./rules/es",
"./rules/import",
"./rules/jsx-a11y",
"./rules/react",
].map(require.resolve),
parser: "babel-eslint",
};
95 changes: 95 additions & 0 deletions rules/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
module.exports = {
plugins: ['babel'],
rules: {
'linebreak-style': 'off',
'func-names': ['error', 'as-needed'],
'prefer-arrow-callback': 'warn',
// 允许连续赋值
'no-multi-assign': 'off',
// 不禁止对函数的参数重新赋值
'no-param-reassign': 'off',
'no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
},
],
'consistent-return': 'off',
'no-unused-vars': [
'warn',
{
vars: 'all',
args: 'after-used',
caughtErrors: 'none',
ignoreRestSiblings: true,
},
],
'global-require': 'off',
'max-len': 'off',
'no-console': [
'warn',
{
allow: ['debug', 'info', 'warn', 'error'],
},
],
'no-bitwise': [
'error',
{
allow: ['~'],
},
],
'no-underscore-dangle': 'off',
'arrow-body-style': 'off',
'default-case': 'off',
// 函数也需要多行尾逗号
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
eqeqeq: [
'warn',
'always',
{
null: 'ignore',
},
],
'no-plusplus': [
'error',
{
allowForLoopAfterthoughts: true,
},
],
'no-multi-spaces': [
'error',
{
ignoreEOLComments: true,
// exceptions: {
// Property: true,
// BinaryExpression: false,
// VariableDeclarator: true,
// ImportDeclaration: true,
// },
},
],
'object-curly-newline': [
'error',
{
multiline: true,
consistent: true,
},
],
// 使用 babel/semi,实例属性需要加分号
semi: 'off',
'babel/semi': ['error', 'always'],
// 强制三元运算符格式
'multiline-ternary': ['error', 'always-multiline'],
},
};
8 changes: 8 additions & 0 deletions rules/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
rules: {
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "off",
"import/extensions": "off",
"import/prefer-default-export": "warn",
},
};
17 changes: 17 additions & 0 deletions rules/jsx-a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
rules: {
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",
"jsx-a11y/anchor-is-valid": [
"error",
{
components: ["Link"],
specialLink: ["to"],
aspects: ["noHref", "invalidHref", "preferButton"],
},
],
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/label-has-for": "off",
"jsx-a11y/label-has-associated-control": "off",
},
};
Loading

0 comments on commit f3ee9c6

Please sign in to comment.