Skip to content

Commit 21a91e7

Browse files
authored
test: eslint setup (#981)
* chore: eslint setup * build: update circleci config * build: fix circleci config
1 parent f88f00d commit 21a91e7

File tree

6 files changed

+1076
-614
lines changed

6 files changed

+1076
-614
lines changed

.circleci/config.yml

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ commands:
2929
- run:
3030
name: Lint project
3131
command: yarn lint
32+
format:
33+
steps:
34+
- run:
35+
name: Format project
36+
command: yarn format
3237
deps:
3338
steps:
3439
- run:
@@ -56,6 +61,7 @@ commands:
5661
- save-cache
5762
- build
5863
- lint
64+
- format
5965
- deps
6066
- test
6167
run-tests:

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/
2+
coverage/
3+
node_modules/
4+
fixtures/

.eslintrc.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module.exports = {
2+
root: true,
3+
plugins: ['@typescript-eslint', 'jest', 'import'],
4+
env: {
5+
es6: true,
6+
node: true
7+
},
8+
parserOptions: {
9+
sourceType: 'module',
10+
ecmaVersion: 11,
11+
ecmaFeatures: {
12+
jsx: false
13+
}
14+
},
15+
extends: ['eslint:recommended', 'prettier'],
16+
rules: {
17+
// disallow non-import statements appearing before import statements
18+
'import/first': 'error',
19+
// Forbid import of modules using absolute paths
20+
'import/no-absolute-path': 'error',
21+
// disallow AMD require/define
22+
'import/no-amd': 'error',
23+
// Forbid mutable exports
24+
'import/no-mutable-exports': 'error',
25+
// Prevent importing the default as if it were named
26+
'import/no-named-default': 'error',
27+
// Forbid a module from importing itself
28+
'import/no-self-import': 'error'
29+
30+
// Enable after https://github.com/benmosher/eslint-plugin-import/issues/1650 is fixed
31+
// Forbid the use of extraneous packages
32+
// 'import/no-extraneous-dependencies': [
33+
// 'error',
34+
// {devDependencies: ['**/*.test.js']}
35+
// ]
36+
},
37+
overrides: [
38+
{
39+
files: ['*.ts'],
40+
parser: '@typescript-eslint/parser',
41+
extends: [
42+
'plugin:@typescript-eslint/eslint-recommended',
43+
'plugin:@typescript-eslint/recommended',
44+
'prettier/@typescript-eslint'
45+
],
46+
rules: {
47+
'@typescript-eslint/no-unused-vars': 'off',
48+
'@typescript-eslint/no-use-before-define': 'off',
49+
'@typescript-eslint/no-explicit-any': 'off',
50+
'@typescript-eslint/explicit-function-return-type': 'off',
51+
'@typescript-eslint/no-var-requires': 'off',
52+
'@typescript-eslint/no-inferrable-types': 'off',
53+
'@typescript-eslint/no-non-null-assertion': 'off',
54+
55+
// TODO: enable those rules?
56+
'no-empty': 'off',
57+
'no-var': 'off'
58+
}
59+
},
60+
{
61+
files: ['*.test.ts', '*.test.js'],
62+
env: {
63+
jest: true
64+
},
65+
extends: ['plugin:jest/recommended'],
66+
rules: {
67+
'@typescript-eslint/no-explicit-any': 'off',
68+
'@typescript-eslint/no-var-requires': 'off',
69+
// disallow non-import statements appearing before import statements
70+
'import/first': 'off'
71+
}
72+
}
73+
]
74+
};

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
lib/
2+
coverage/
3+
node_modules/
4+
fixtures/
25
CHANGELOG.md

package.json

+14-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"deps": "lerna run deps",
1313
"pkg": "lerna run pkg",
1414
"docs": "docsify serve docs",
15-
"lint": "prettier **/*.{ts,js,json,yml,md} -l",
15+
"lint": "eslint . --ext .js,.ts",
16+
"lint-fix": "eslint . --ext .js,.ts --fix",
17+
"format": "prettier **/*.{ts,js,json,yml,md} -l",
18+
"format-fix": "prettier **/*.{ts,js,json,yml,md} --write",
1619
"publish": "lerna publish --conventional-commits",
1720
"reinstall": "yarn clean && yarn install",
1821
"start": "lerna run start --stream --parallel --include-dependencies",
@@ -75,18 +78,24 @@
7578
},
7679
"devDependencies": {
7780
"@lerna/project": "3.18.0",
78-
"@types/node": "12.12.26",
7981
"@types/jest": "25.1.2",
82+
"@types/node": "12.12.26",
83+
"@typescript-eslint/eslint-plugin": "^2.19.0",
84+
"@typescript-eslint/parser": "^2.19.0",
8085
"docsify-cli": "^4.4.0",
86+
"eslint": "^6.8.0",
87+
"eslint-config-prettier": "^6.10.0",
88+
"eslint-plugin-import": "^2.20.1",
89+
"eslint-plugin-jest": "^23.6.0",
8190
"husky": "4.2.1",
8291
"jest": "25.1.0",
8392
"lerna": "3.20.2",
93+
"lerna-v2": "npm:lerna@2",
94+
"lerna-v3": "npm:lerna@3",
8495
"lint-staged": "10.0.7",
8596
"prettier": "1.17.1",
8697
"ts-jest": "25.2.0",
87-
"typescript": "3.7.5",
88-
"lerna-v2": "npm:lerna@2",
89-
"lerna-v3": "npm:lerna@3"
98+
"typescript": "3.7.5"
9099
},
91100
"husky": {
92101
"hooks": {

0 commit comments

Comments
 (0)