-
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: format with new eslint rules * feat: update prettier * feat: add new rule for node-mjs * feat: update lintstaged * chore: add eslint-plugin-mdx * feat: test * feat: test * feat: del test case * feat: add eslint-plugin-mdx * docs: update * fix: typo * docs: update * feat: update @typescript-eslint/parser parserOption.project
- Loading branch information
Showing
43 changed files
with
1,097 additions
and
408 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 |
---|---|---|
@@ -1 +1,5 @@ | ||
# by default, .eslintrc will ignored | ||
!.eslintrc.js | ||
|
||
# build assets should not lint | ||
dist/ |
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 @@ | ||
const { babel, typescript } = require('@mjolnir/eslint-config/overrides'); | ||
|
||
module.exports = { | ||
extends: ['@mjolnir'], | ||
overrides: [babel, typescript], | ||
rules: {}, | ||
}; |
This file was deleted.
Oops, something went wrong.
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,7 +1,15 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/lintstagedrc.schema", | ||
"**/*.{js, ts}": [ | ||
"*.{js,ts}": [ | ||
"eslint --fix", | ||
"git add" | ||
], | ||
".*rc": [ | ||
"prettier --write", | ||
"git add" | ||
], | ||
"*.{html,json,md,mdx,yaml,yml}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
} |
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,5 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = api => { | ||
api.cache(false); | ||
|
||
|
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
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,5 +1,3 @@ | ||
'use strict'; | ||
|
||
const { declare } = require('@babel/helper-plugin-utils'); | ||
const env = process.env.NODE_ENV; | ||
|
||
|
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,90 +1,154 @@ | ||
# @mjolnir/eslint-config | ||
|
||
适用于 node/es/ts/react 环境下的 eslint 配置集合。 | ||
适用于 web 开发的 eslint 配置集合: | ||
|
||
- 内置了对 node, markdown, pretier 的 lint。 | ||
- 通过 overrides, 支持 babel/typescript/react/jest/mdx 的 lint. | ||
|
||
## 说明 | ||
### requirement | ||
- eslint@6 | ||
|
||
### 包含的插件 | ||
- "@typescript-eslint/eslint-plugin": "^1.13.0" | ||
- "@typescript-eslint/parser": "^1.13.0" | ||
- "eslint-plugin-babel": "^5.3.0" | ||
- "eslint-plugin-import": "^2.18.2" | ||
- "eslint-plugin-node": "^9.1.0" | ||
- "eslint-plugin-react": "^7.14.3" | ||
- "eslint-plugin-react-hooks": "^1.7.0" | ||
|
||
## requirement | ||
|
||
- eslint | ||
- prettier | ||
|
||
### dependencies | ||
|
||
``` | ||
@typescript-eslint/eslint-plugin | ||
@typescript-eslint/parser | ||
babel-eslint | ||
eslint-plugin-babel | ||
eslint-plugin-import | ||
eslint-plugin-jest | ||
eslint-plugin-node | ||
eslint-plugin-react | ||
eslint-plugin-react-hooks | ||
eslint-config-prettier | ||
eslint-plugin-prettier | ||
eslint-plugin-mdx | ||
``` | ||
|
||
## 安装 | ||
|
||
`yarn add eslint @mjolnir/eslint-config -D` | ||
|
||
or | ||
|
||
`npm i eslint @mjolnir/eslint-config -D` | ||
|
||
## 配置 | ||
### es6 (默认) | ||
```json | ||
|
||
### es6/node (默认) | ||
|
||
适用于 web 开发, 基于 ES6 Module 模块化方式。 | ||
|
||
```jsonc | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config" | ||
] | ||
"extends": ["@mjolnir"] // same as @mjolnir/eslint-config | ||
} | ||
``` | ||
|
||
### Node.js with commonJS | ||
|
||
纯 node 项目, 使用 commonJS 模块化方式。 | ||
|
||
### Node.js | ||
```json | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config/node" | ||
] | ||
"extends": ["@mjolnir/eslint-config/node"] | ||
} | ||
``` | ||
|
||
## overrides 配置 | ||
|
||
通过提供 `overrides` 的方式,增强对 `babel`, `typescript`, react`,`jest`项目的支持。 配置文件需要使用`.eslintrc.js` 格式。 | ||
|
||
### recommended | ||
|
||
推荐的 override 配置项,包含: | ||
|
||
- babel | ||
- typescript | ||
- react | ||
- jest | ||
- mdx | ||
|
||
适用于 Jest 项目,处理的文件类型: `**/*.{spec,test}.{js,jsx,ts,tsx}`. | ||
|
||
```js | ||
const { recommended } = require('@mjolnir/eslint-config/overrides'); | ||
{ | ||
..., | ||
"overrides": recommended | ||
} | ||
``` | ||
|
||
### Babel (ES) | ||
```json | ||
|
||
适用 babel 的项目, 处理的文件为: `**/*.{js, jsx}`. | ||
|
||
```js | ||
const { babel } = require('@mjolnir/eslint-config/overrides'); | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config/babel" | ||
..., | ||
"overrides": [ | ||
babel | ||
] | ||
} | ||
``` | ||
|
||
### TypeScript | ||
```json | ||
|
||
适用 typescript 的项目, 处理的文件为: `**/*.ts?(x)`. | ||
|
||
```js | ||
const { typescript } = require('@mjolnir/eslint-config/overrides'); | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config/typescript" | ||
..., | ||
"overrides": [ | ||
typescript | ||
] | ||
} | ||
``` | ||
|
||
### React | ||
```json | ||
|
||
适用于 react 项目, 处理的文件为: `**/*.{js,jsx,ts,tsx}`. | ||
|
||
```js | ||
const { react } = require('@mjolnir/eslint-config/overrides'); | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config/babel", | ||
"@mjolnir/eslint-config/react" | ||
..., | ||
"overrides": [ | ||
react | ||
] | ||
} | ||
``` | ||
|
||
### React with TypeScript | ||
```json | ||
### Jest | ||
|
||
适用于 Jest 项目,处理的文件类型: `**/*.{spec,test}.{js,jsx,ts,tsx}`. | ||
|
||
```js | ||
const { jest } = require('@mjolnir/eslint-config/overrides'); | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config/typescript", | ||
"@mjolnir/eslint-config/react" | ||
..., | ||
"overrides": [ | ||
jest | ||
] | ||
} | ||
``` | ||
|
||
### jest 环境 | ||
```json | ||
### mdx | ||
|
||
适用于 mdx 文件,处理的文件类型: `*.mdx`. | ||
|
||
```js | ||
const { mdx } = require('@mjolnir/eslint-config/overrides'); | ||
{ | ||
"extends": [ | ||
"@mjolnir/eslint-config/jest" | ||
..., | ||
"overrides": [ | ||
mdx | ||
] | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
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,20 +1,24 @@ | ||
'use strict'; | ||
|
||
// for es6 env | ||
// for es6 and node env | ||
module.exports = { | ||
root: true, // limit ESLint to a specific project | ||
env: { | ||
node: true, | ||
browser: true, | ||
es6: true, // also enable ecmaVersion: 6 | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018, // same as 9 | ||
sourceType: 'module', // ECMAScript module | ||
ecmaFeatures: { | ||
globalReturn: false, | ||
impliedStrict: true, | ||
jsx: true, | ||
}, | ||
}, | ||
extends: ['./rules', './plugins/import'].map(require.resolve), | ||
extends: [ | ||
'./rules', | ||
'./plugins/node-mjs', | ||
'./plugins/import', | ||
'./plugins/markdown', | ||
'./plugins/prettier', | ||
].map(require.resolve), | ||
}; |
This file was deleted.
Oops, something went wrong.
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,8 +1,21 @@ | ||
'use strict'; | ||
|
||
// for nodejs env, support es6+ syntax | ||
// for nodejs with commonJS | ||
module.exports = { | ||
root: true, // limit ESLint to a specific project | ||
extends: ['./rules', './plugins/node'].map(require.resolve), | ||
rules: {}, | ||
env: { | ||
node: true, | ||
es6: true, // also enable ecmaVersion: 6 | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018, // same as 9 | ||
ecmaFeatures: { | ||
globalReturn: true, | ||
impliedStrict: true, | ||
}, | ||
}, | ||
extends: [ | ||
'./rules', | ||
'./plugins/node-cjs', | ||
'./plugins/markdown', | ||
'./plugins/prettier', | ||
].map(require.resolve), | ||
}; |
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,5 @@ | ||
// for babel env, base on es6 env | ||
module.exports = { | ||
files: ['*.{js,jsx}'], | ||
extends: ['../plugins/babel'].map(require.resolve), | ||
}; |
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,14 @@ | ||
// TODO: shareable config 里面暂时无法使用 extends , 所以交给项目配置 | ||
module.exports = { | ||
typescript: require('./typescript'), | ||
babel: require('./babel'), | ||
jest: require('./jest'), | ||
react: require('./react'), | ||
mdx: require('./mdx'), | ||
recommended: [ | ||
require('./typescript'), | ||
require('./babel'), | ||
require('./jest'), | ||
require('./mdx'), | ||
], | ||
}; |
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,5 @@ | ||
// for jest env | ||
module.exports = { | ||
files: ['*.{spec,test}.{js,jsx,ts,tsx}'], | ||
extends: ['../plugins/jest'].map(require.resolve), | ||
}; |
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,9 @@ | ||
// mdx lint jsx in markdown | ||
module.exports = { | ||
files: ['*.mdx'], | ||
extends: [ | ||
...['../plugins/react', '../plugins/react-hooks'].map(require.resolve), | ||
'plugin:mdx/recommended', | ||
'plugin:mdx/overrides', | ||
], | ||
}; |
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,5 @@ | ||
// for react env | ||
module.exports = { | ||
files: ['*.{js,jsx,ts,tsx}'], | ||
extends: ['../plugins/react', '../plugins/react-hooks'].map(require.resolve), | ||
}; |
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,5 @@ | ||
// for typescript env, base on es6 env | ||
module.exports = { | ||
files: ['*.ts?(x)'], | ||
extends: ['../plugins/typescript'].map(require.resolve), | ||
}; |
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
Oops, something went wrong.