Skip to content

Commit 2eb4568

Browse files
6.0.0 Proper Prettier & ESLint
1 parent e3527a2 commit 2eb4568

File tree

8 files changed

+2590
-2843
lines changed

8 files changed

+2590
-2843
lines changed

eslint-config-ringcentral-typescript/README.md

+34-35
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ RingCentral TypeScript
33

44
A stricter and TypeScript-enabled version of https://github.com/ringcentral/ringcentral-javascript.
55

6+
Starting with version `6.x` we obey the [recommended prettier approach](https://prettier.io/docs/en/integrating-with-linters.html): disable ESLint's style-related rules + separate prettier executable (previously prettier tasks were also executed by ESLint).
7+
68
## Installation
79

810
```bash
9-
$ npm install eslint eslint-config-ringcentral-typescript --save-dev
11+
$ yarn add eslint prettier eslint-config-ringcentral-typescript -D
1012
```
1113

1214
Add this to `scripts` section of `package.json`:
1315

1416
```json
1517
{
1618
"scripts": {
17-
"lint": "eslint --cache --cache-location node_modules/.cache/eslint --fix ",
18-
"lint:all": "npm run lint 'src/**/*.ts' 'src/**/*.tsx'"
19+
"prettier": "prettier --write",
20+
"eslint": "eslint --cache --cache-location node_modules/.cache/eslint --fix",
21+
"lint:all": "yarn prettier --write . && yarn eslint --fix .",
22+
"lint:staged": "lint-staged --debug"
1923
}
2024
}
2125
```
@@ -25,6 +29,17 @@ You can add `DEBUG=eslint:cli-engine` to output files that were linted.
2529

2630
:warning: Please note commas around globs: `'src/**/*.ts'`, this will prevent your OS to expand those globs.
2731

32+
Add `.eslintignore` and `.prettierignore` files, both usually look like this:
33+
34+
```gitignore
35+
.husky
36+
.pnp.js
37+
.yarn
38+
coverage
39+
node_modules
40+
storybook-static
41+
dist
42+
```
2843
Create `.eslintrc`:
2944

3045
```json
@@ -35,27 +50,13 @@ Create `.eslintrc`:
3550
}
3651
```
3752

38-
Create `.prettierrc` (optional):
39-
40-
```bash
41-
{
42-
"printWidth": 120
43-
}
44-
```
45-
46-
:warning: Keep in mind that anything you set in `.prettierrc` may be overridden by config specified in this repo.
47-
48-
You may use following trick in `.eslintrc` if you need to take control:
53+
Create `.prettierrc.js` (optional):
4954

5055
```js
51-
const prettierOptions = JSON.parse(require('fs').readFileSync('./.prettierrc').toString());
52-
5356
module.exports = {
54-
...
55-
rules: {
56-
'prettier/prettier': ['warn', Object.assign({}, prettierOptions)]
57-
}
58-
};
57+
...require('eslint-config-ringcentral-typescript/src/prettier'),
58+
// overrides if needed
59+
}
5960
```
6061

6162
Create a `.editorconfig` (optional):
@@ -73,7 +74,7 @@ insert_final_newline = false
7374
[*.{js,jsx,ts,tsx}]
7475
indent_size = 4
7576

76-
[*.{css,sass,scss,yml,json}]
77+
[*.{css,sass,scss,less,yml,json,md}]
7778
indent_size = 2
7879

7980
[Makefile]
@@ -85,37 +86,35 @@ indent_style = tab
8586
Works best when used together with [Husky](https://github.com/typicode/husky) and [Lint Staged](https://github.com/okonet/lint-staged):
8687

8788
```bash
88-
$ npm install husky lint-staged --save-dev
89+
$ yarn add husky lint-staged -D
8990
```
9091

9192
Add this to `scripts` section of `package.json`:
9293

93-
```json
94+
```json5
9495
{
9596
"scripts": {
97+
"prepare": "husky install", // yarn 1 and npm
98+
"postinstall": "husky install", // yarn 2 private packages
9699
"lint:staged": "lint-staged"
97100
}
98101
}
99102
```
100103

101-
Create `.huskyrc`:
104+
See Husky documentation for detailed instructions for [Yarn 2 and public package](https://typicode.github.io/husky/#/?id=yarn-2).
102105

103-
```json
104-
{
105-
"hooks": {
106-
"pre-commit": "npm run lint:staged"
107-
}
108-
}
106+
Create `.husky/pre-commit`:
107+
108+
```bash
109+
yarn lint:staged
109110
```
110111

111112
Create `.lintstagedrc`:
112113

113114
```json
114115
{
115-
"*.{js,jsx,ts,tsx}": [
116-
"npm run lint --",
117-
"git add"
118-
]
116+
"*.{js,jsx,ts,tsx,css,scss,sass,less,md,yml,json}": ["yarn prettier", "git add"],
117+
"*.{js,jsx,ts,tsx}": ["yarn eslint", "git add"]
119118
}
120119
```
121120

eslint-config-ringcentral-typescript/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
"eslint-config-ringcentral": "1.0.0",
1818
"eslint-import-resolver-node": "0.3.4",
1919
"eslint-plugin-flowtype": "5.2.0",
20-
"eslint-plugin-import": "2.22.1",
20+
"eslint-plugin-import": "2.24.2",
2121
"eslint-plugin-jest": "24.1.3",
2222
"eslint-plugin-jsx-a11y": "6.4.1",
2323
"eslint-plugin-prettier": "3.3.1",
24-
"eslint-plugin-react": "7.22.0",
24+
"eslint-plugin-react": "7.25.1",
2525
"eslint-plugin-react-hooks": "4.2.0",
2626
"eslint-plugin-testing-library": "3.10.1",
2727
"eslint-plugin-ringcentral": "1.0.0",
2828
"eslint-plugin-sonarjs": "0.5.0",
29-
"prettier": "2.2.1"
29+
"prettier": "2.4.0"
3030
},
3131
"peerDependencies": {
3232
"eslint": "*",

eslint-config-ringcentral-typescript/src/config.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,18 @@ require('@rushstack/eslint-patch/modern-module-resolution');
22

33
module.exports = {
44
root: true,
5-
plugins: ['prettier'], //FIXME [UIA-10000] Remove
65
extends: [
76
require.resolve('eslint/conf/eslint-recommended'),
87
'plugin:import/recommended',
98
'plugin:jsx-a11y/recommended',
109
'plugin:react/recommended',
1110
require.resolve('eslint-config-react-app'),
1211
require.resolve('eslint-config-ringcentral'),
13-
// 'plugin:prettier/recommended', // must be below ringcentral to override react prefs
14-
require.resolve('eslint-config-prettier'), // must be below ringcentral to override react prefs
15-
require.resolve('eslint-config-prettier/react'), // must be below ringcentral to override react prefs
1612
'plugin:@typescript-eslint/recommended', // must be below react-app & ringcentral to enable proper parser
17-
'plugin:import/typescript',
13+
require.resolve('eslint-config-prettier'), // must be below ringcentral to override react prefs
1814
],
1915
rules: {
2016
curly: 'error',
21-
'prettier/prettier': [
22-
'error',
23-
{
24-
bracketSpacing: false,
25-
parser: 'typescript',
26-
singleQuote: true,
27-
tabWidth: 4,
28-
trailingComma: 'all',
29-
},
30-
],
3117
'no-shadow': 'off',
3218
'@typescript-eslint/ban-types': 'off',
3319
'@typescript-eslint/indent': 'off', // prettier takes care of it
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
singleQuote: true,
4+
tabWidth: 2,
5+
trailingComma: 'all',
6+
overrides: [
7+
{
8+
files: '*.{js,jsx,ts,tsx,html}',
9+
options: {
10+
tabWidth: 4
11+
}
12+
}
13+
]
14+
};

eslint-config-ringcentral/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
"homepage": "https://github.com/ringcentral/ringcentral-javascript",
2929
"devDependencies": {
3030
"eslint": "^7.11.0",
31-
"eslint-plugin-import": "^2.22.1",
32-
"eslint-plugin-react": "^7.21.4",
31+
"eslint-plugin-import": "^2.24.2",
32+
"eslint-plugin-react": "^7.25.1",
3333
"eslint-plugin-ringcentral": "^1.0.0",
34-
"eslint-plugin-sonarjs": "^0.5.0"
34+
"eslint-plugin-sonarjs": "0.5.0"
3535
},
3636
"peerDependencies": {
3737
"eslint": "^7.11.0",

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"lerna": "3.19.0",
33
"useWorkspaces": true,
44
"npmClient": "yarn",
5-
"version": "0.0.0"
5+
"version": "1.0.0"
66
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"publish:release": "lerna publish --tag-version-prefix=\"\" --force-publish=* --no-push --no-git-tag-version"
99
},
1010
"dependencies": {
11-
"lerna": "3.19.0"
11+
"lerna": "4.0.0"
1212
},
1313
"repository": {
1414
"type": "git",

0 commit comments

Comments
 (0)