Skip to content

Commit

Permalink
feat: feat(eslint-midway-contrib): add pkg for js and ts (#397)
Browse files Browse the repository at this point in the history
* feat(eslint-midway-contrib): add pkg for js and ts

* chore(eslint-midway-contrib): add .eslintrc.yml.sample

* build(eslint-midway-contrib): add pkg.files

* chore(eslint-midway-contrib): update README.md and samples

(cherry picked from commit 6b32262)
  • Loading branch information
waitingsong authored and czy88840616 committed Mar 5, 2020
1 parent 6e77d36 commit 3b404a5
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"autocannon": "^2.4.1",
"chalk": "^3.0.0",
"debug": "^4.1.1",
"eslint": "6",
"gh-pages": "^1.2.0",
"git-hooks": "^1.1.10",
"lerna": "^3.14.1",
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-midway-contrib/.eslintrc.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends: 'eslint-midway-contrib'
parserOptions:
project: 'tsconfig.eslint.json'

# https://eslint.org/docs/rules/
# https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
# https://github.com/benmosher/eslint-plugin-import
# https://github.com/sindresorhus/eslint-plugin-unicorn
rules:
unicorn/filename-case: 2
# Use tsconfig.json noUnusedLocals:true instead
"@typescript-eslint/no-unused-vars": 0

30 changes: 30 additions & 0 deletions packages/eslint-midway-contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# eslint-midway-contrib

[![Package Quality](http://npm.packagequality.com/shield/eslint-midway-contrib.svg)](http://packagequality.com/#?package=eslint-midway-contrib)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)

This is a sub package for midway.

Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)


## Install

```bash
tnpm i eslint eslint-midway-contrib --save-dev
```


## Usage

### Configurations for TypeScript project

Create `.eslintrc.yml` and `tsconfig.eslint.json` under the project

- [`.eslintrc.yml.sample`](./.eslintrc.yml.sample)
- [`tsconfig.eslint.json.smaple`](./tsconfig.eslint.json.sample)


## License

[MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
31 changes: 31 additions & 0 deletions packages/eslint-midway-contrib/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
node: true,
},
extends: ['./plugins/import.yml'],
globals: {
Atomics: 'readonly',
document: 'readonly',
globalThis: 'readonly',
navigator: 'readonly',
SharedArrayBuffer: 'readonly',
window: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
globalReturn: false,
impliedStrict: true,
},
ecmaVersion: 2019,
// see: https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.0.0
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'unicorn'],
root: true,
};

5 changes: 5 additions & 0 deletions packages/eslint-midway-contrib/eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"./strict.js"
]
}
3 changes: 3 additions & 0 deletions packages/eslint-midway-contrib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* eslint-disable-next-line @typescript-eslint/no-require-imports */
module.exports = require('./strict.js');

54 changes: 54 additions & 0 deletions packages/eslint-midway-contrib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "eslint-midway-contrib",
"version": "0.0.0",
"description": "ESlint default rule for midway",
"keywords": [
"ECMAScript Style",
"code style",
"eslint",
"eslintconfig",
"midway",
"typescript"
],
"engines": {
"node": ">=8.10.0"
},
"main": "index.js",
"bugs": {
"url": "https://https://github.com/midwayjs/midway/issues"
},
"homepage": "https://https://github.com/midwayjs/midway#readme",
"repository": {
"type": "git",
"url": "https://github.com/midwayjs/midway.git"
},
"license": "MIT",
"author": "waiting",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-unicorn": "^16.0.0"
},
"devDependencies": {
"eslint": "6",
"tape": "4",
"typescript": "3"
},
"peerDependencies": {
"eslint": ">=6.1.0"
},
"files": [
"plugins/*.yml",
"*.js"
],
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"lint": "eslint --fix . --config=recommended.js && eslint --fix . --config=strict.js",
"prepublishOnly": "npm run test",
"test": "npm run lint && tape test/*.js"
}
}
45 changes: 45 additions & 0 deletions packages/eslint-midway-contrib/plugins/import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
extends:
- plugin:import/errors
- plugin:import/warnings
- plugin:import/typescript # this line does the trick


rules:
# https://github.com/benmosher/eslint-plugin-import#static-analysis
import/default: 2
import/named: 2
import/namespace: 0
import/no-unresolved: [0, {"amd": true, "commonjs": true}]
import/no-absolute-path: 2
import/no-cycle: 0
import/no-self-import: 2
import/no-useless-path-segments: 2

# https://github.com/benmosher/eslint-plugin-import#helpful-warnings
import/export: 2
import/no-deprecated: 0
import/no-mutable-exports: 2
import/no-named-as-default: 2
import/no-named-as-default-member: 2

# https://github.com/benmosher/eslint-plugin-import#style-guide
import/exports-last: 0
import/first: 2
import/newline-after-import: [1, { "count": 2 } ]
import/no-default-export: 0
import/no-duplicates: 1
import/no-extraneous-dependencies: 0
import/no-named-default: 2
import/no-namespace: 0
import/order:
- 1
- groups:
- builtin
- external
- internal
- parent
- sibling
- index
newlines-between: always

154 changes: 154 additions & 0 deletions packages/eslint-midway-contrib/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
module.exports = {
extends: [
'./base.js',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'sort-imports': 0,
'require-atomic-updates': 0,

// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
'@typescript-eslint/array-type': [2],
'brace-style': 0,
'@typescript-eslint/brace-style': [1, 'stroustrup', { allowSingleLine: true } ],
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/consistent-type-definitions': [2, 'interface'],
'@typescript-eslint/explicit-function-return-type': 0,
'func-call-spacing': 0,
'@typescript-eslint/func-call-spacing': [1, 'never'],
indent: 0,
'@typescript-eslint/indent': [2, 2, { SwitchCase: 1 } ],
'@typescript-eslint/member-delimiter-style': [
2,
{
overrides: {
interface: {
multiline: {
delimiter: 'none',
requireLast: false,
},
},
},
},
],
'no-empty-function': 0,
'@typescript-eslint/no-empty-function': 1,
'@typescript-eslint/no-explicit-any': [0],
'no-extra-parens': 0,
'@typescript-eslint/no-extra-parens': 2,
'@typescript-eslint/no-parameter-properties': 0,
'no-use-before-define': 0,
'@typescript-eslint/no-use-before-define': [2, { functions: false, typedefs: false } ],
semi: 0,
'@typescript-eslint/semi': [1, 'always'],

// https://eslint.org/docs/rules/#best-practices
curly: 2,
'dot-notation': 1,
eqeqeq: 2,
'no-eval': 2,
'no-multi-spaces': 1,
'no-throw-literal': 2,
'no-unmodified-loop-condition': 2,

// https://eslint.org/docs/rules/#variables
'no-restricted-globals': [2, 'isFinite', 'isNaN'],
'no-shadow': 2,

// https://eslint.org/docs/rules/#stylistic-issues
'array-bracket-newline': [1, { multiline: true } ],
'array-bracket-spacing': [1, 'never', { singleValue: false, objectsInArrays: true, arraysInArrays: true } ],
'block-spacing': 1,
'comma-dangle': [
1, {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
'comma-spacing': 1,
'comma-style': 1,
'computed-property-spacing': 1,
'eol-last': [1, 'always'],
'function-paren-newline': [1, 'multiline-arguments'],
'implicit-arrow-linebreak': 2,
'key-spacing': 1,
'keyword-spacing': 1,
'linebreak-style': [1, 'unix'],
'new-parens': [1],
'newline-per-chained-call': [1, { ignoreChainWithDepth: 6 } ],
'no-mixed-spaces-and-tabs': 2,
'no-multiple-empty-lines': [1, { max: 4, maxBOF: 1, maxEOF: 1 } ],
'no-trailing-spaces': [2, { skipBlankLines: false, ignoreComments: true } ],
'no-whitespace-before-property': 1,
'object-curly-newline': [
1,
{
ObjectExpression: { multiline: true, minProperties: 4, consistent: true },
ObjectPattern: { multiline: true, minProperties: 4, consistent: true },
ImportDeclaration: { multiline: true, minProperties: 6 },
ExportDeclaration: { multiline: true, minProperties: 2 },
},
],
'object-curly-spacing': [1, 'always'],
'object-property-newline': [1, { allowAllPropertiesOnSameLine: true } ],
'quote-props': [1, 'as-needed'],
quotes: [1, 'single'],
'semi-spacing': [1, { before: false, after: true } ],
'semi-style': [2, 'last'],
'space-before-blocks': [1, 'always'],
'space-before-function-paren': [
1, {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
'spaced-comment': [
1, 'always',
{
line: {
markers: ['/'],
exceptions: ['-', '+'],
},
block: {
markers: ['!'],
exceptions: ['*'],
balanced: true,
},
},
],
'space-in-parens': [1, 'never'],
'space-infix-ops': [1],
'space-unary-ops': [
2,
{
words: true,
nonwords: false,
overrides: {
'!': true,
'!!': true,
},
},
],
'template-tag-spacing': [1, 'never'],
'unicode-bom': [2, 'never'],

// https://eslint.org/docs/rules/#ecmascript-6
'arrow-body-style': [0, 'as-needed', { requireReturnForObjectLiteral: true } ],
'arrow-parens': [1, 'as-needed', { requireForBlockBody: true } ],
'arrow-spacing': 1,
// conflict with @typescript-eslint/no-extra-parens
'no-confusing-arrow': [0, { allowParens: true } ],
'no-duplicate-imports': 2,
'no-useless-computed-key': 1,
'no-useless-rename': 1,
'no-var': 2,
'object-shorthand': [1, 'always'],
},
};

Loading

0 comments on commit 3b404a5

Please sign in to comment.