Skip to content

Commit

Permalink
添加 @mjolnir/eslint-config (#1)
Browse files Browse the repository at this point in the history
* feat(lerna): update README

* feat(vscode): add vscode settings

* feat: add rules and plugins for base config

* feat: add react config

* feat: use independent version for lerna

* feat: add useage

* chore(vscode): update eslint settings

* chore(npm): add lerna-changelog

* chore: add lerna-changelog script
  • Loading branch information
leohxj authored Jul 23, 2019
1 parent f125e6c commit 40fbcb1
Show file tree
Hide file tree
Showing 32 changed files with 8,257 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"eslint.validate": [
{ "language": "javascript", "autoFix": true },
{ "language": "javascriptreact", "autoFix": true },
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
],
"cSpell.words": [
"mjolnir"
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# mjolnir
# mjolnir [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)

A tool for FrondEnd Developer, same as the "Thor Hammer".
7 changes: 6 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"changelog": {
"repo": "mjolnirjs/mjolnir",
"cacheDir": ".changelog"
},
"packages": [
"packages/*"
],
"version": "0.0.0"
"npmClient": "yarn",
"version": "independent"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"name": "root",
"private": true,
"devDependencies": {
"lerna": "^3.15.0"
"lerna": "^3.15.0",
"lerna-changelog": "^0.8.2"
},
"scripts": {
"lerna": "lerna",
"changelog": "lerna-changelog",
"bootstrap": "lerna bootstrap",
"update": "lerna updated",
"publish": "lerna publish",
Expand Down
File renamed without changes.
Empty file.
16 changes: 16 additions & 0 deletions packages/eslint-config/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
6 changes: 6 additions & 0 deletions packages/eslint-config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: [
'./node.js',
"plugin:prettier/recommended"
]
};
23 changes: 23 additions & 0 deletions packages/eslint-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
5 changes: 5 additions & 0 deletions packages/eslint-config/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/*.md
**/*.svg
**/*.ejs
**/*.html
package.json
5 changes: 5 additions & 0 deletions packages/eslint-config/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 80,
"singleQuote": true,
"arrowParens": "always"
}
84 changes: 84 additions & 0 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# @mjolnir/eslint-config

适用于 node/es/ts/react 环境下的 eslint 配置集合。

## 使用说明
按环境区分使用

### es6 (默认)
`npm i -D @mjolnir/eslint-config eslint eslint-plugin-import`

#### 配置
```json
{
"extends": [
"@mjolnir/eslint-config"
]
}
```


### Node.js
`npm i -D @mjolnir/eslint-config eslint eslint-plugin-node`

#### 配置
```json
{
"extends": [
"@mjolnir/eslint-config/node"
]
}
```

### Babel (ES)
`npm i -D @mjolnir/eslint-config eslint eslint-plugin-import babel-eslint eslint-plugin-babel`

#### 配置
```json
{
"extends": [
"@mjolnir/eslint-config/babel"
]
}
```

### TypeScript
`npm i -D @mjolnir/eslint-config eslint eslint-plugin-import @typescript-eslint/parser @typescript-eslint/eslint-plugin`

#### 配置
```json
{
"extends": [
"@mjolnir/eslint-config/typescript"
]
}
```

### React
`npm i -D @mjolnir/eslint-config eslint eslint-plugin-import babel-eslint eslint-plugin-babel eslint-plugin-react eslint-plugin-react-hook`

#### 配置
```json
{
"extends": [
"@mjolnir/eslint-config/babel",
"@mjolnir/eslint-config/react"
]
}
```



### React with TypeScript
`npm i -D @mjolnir/eslint-config eslint eslint-plugin-import @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-plugin-react-hook`

#### 配置
```json
{
"extends": [
"@mjolnir/eslint-config/typescript",
"@mjolnir/eslint-config/react"
]
}
```

6 changes: 6 additions & 0 deletions packages/eslint-config/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: [
'./index', // 基于 es6 的配置
'./plugins/babel'
].map(require.resolve)
};
15 changes: 15 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// for es6 env
module.exports = {
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
env: {
browser: true,
es6: true
},
extends: ['./rules', './plugins/import'].map(require.resolve)
};
4 changes: 4 additions & 0 deletions packages/eslint-config/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// for nodejs env, support es6+ syntax
module.exports = {
extends: ['./rules', './plugins/node'].map(require.resolve)
};
35 changes: 35 additions & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@mjolnir/eslint-config",
"version": "0.0.1",
"description": "eslint config collect",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/mjolnirjs/mjolnir/tree/master/packages/eslint-config"
},
"homepage": "https://github.com/mjolnirjs/mjolnir/tree/master/packages/eslint-config",
"bugs": {
"url": "https://github.com/mjolnirjs/mjolnir/issues"
},
"keywords": [
"eslint",
"config",
"airbnb",
"javascript"
],
"license": "MIT",
"dependencies": {},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-plugin-node": "^9.1.0",
"eslint-config-prettier": "^4.3.0",
"eslint-plugin-prettier": "^3.1.0",
"prettier": "^1.17.1"
},
"peerDependencies": {
"eslint": "^5.16.0"
},
"publishConfig": {
"access": "public"
}
}
6 changes: 6 additions & 0 deletions packages/eslint-config/plugins/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// eslint-plugin-babel has no recommend config
module.exports = {
parser: 'babel-eslint',
plugins: ['babel'],
rules: {}
};
16 changes: 16 additions & 0 deletions packages/eslint-config/plugins/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
plugins: ['import'],
rules: {
// analysis/correctness
'import/no-unresolved': 'error',
'import/named': 'error',
'import/namespace': 'error',
'import/default': 'error',
'import/export': 'error',

// red flags (thus, warnings)
'import/no-named-as-default': 'warn',
'import/no-named-as-default-member': 'warn',
'import/no-duplicates': 'warn'
}
};
40 changes: 40 additions & 0 deletions packages/eslint-config/plugins/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
extends: ['plugin:node/recommended'],
rules: {
// enforce return after a callback
'callback-return': 'off',

// require all requires be top-level
// https://eslint.org/docs/rules/global-require
'global-require': 'error',

// enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',

// disallow use of the Buffer() constructor
// https://eslint.org/docs/rules/no-buffer-constructor
'no-buffer-constructor': 'error',

// disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],

// disallow use of new operator with the require function
'no-new-require': 'error',

// disallow string concatenation with __dirname and __filename
// https://eslint.org/docs/rules/no-path-concat
'no-path-concat': 'error',

// disallow use of process.env
'no-process-env': 'off',

// disallow process.exit()
'no-process-exit': 'off',

// restrict usage of specified node modules
'no-restricted-modules': 'off',

// disallow use of synchronous methods (off by default)
'no-sync': 'off'
}
};
7 changes: 7 additions & 0 deletions packages/eslint-config/plugins/react-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
plugins: ['react-hooks'],
rules: {
'react-hooks/exhaustive-deps': 'warn',
'react-hooks/rules-of-hooks': 'error'
}
};
Loading

0 comments on commit 40fbcb1

Please sign in to comment.