Skip to content

Commit e1586c9

Browse files
CatchMe2Mateusz Tkacz
and
Mateusz Tkacz
authored
change prettier handling (#23)
* feat: change prettier handling * chore: add prettier formatting to all supported file types * feat: remove index.js with react-ts config * chore: add info about peerDeps plugins * chore: remove unneeded off rules in rn config Co-authored-by: Mateusz Tkacz <mateusz.tkacz@mobilereality.pl>
1 parent 4c17b02 commit e1586c9

13 files changed

+592
-722
lines changed

.prettierignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
.idea
21
node_modules
32
.husky
4-
package-lock.json
5-
README.md
6-
LICENSE.md
3+
.idea

.prettierrc

-8
This file was deleted.

.prettierrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
trailingComma: 'all',
3+
jsxSingleQuote: false,
4+
singleQuote: true,
5+
bracketSameLine: false,
6+
printWidth: 80,
7+
tabWidth: 4,
8+
};

README.md

+63-55
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# @mobile-reality/eslint-config
2+
23
[![Version](https://img.shields.io/npm/v/@mobile-reality/eslint-config?style=for-the-badge)](https://www.npmjs.com/package/@mobile-reality/eslint-config)
34
[![GitHub stars](https://img.shields.io/github/stars/MobileReality/eslint-config?style=for-the-badge)](https://github.com/MobileReality/react-native-select-pro/stargazers)
45
[![npm total downloads](https://img.shields.io/npm/dt/@mobile-reality/eslint-config?style=for-the-badge)](https://www.npmjs.com/package/@mobile-reality/eslint-config)
@@ -13,86 +14,93 @@ ESLint's configuration of Mobile Reality Team
1314
---
1415

1516
## Table of Contents
16-
- [Requirements](#requirements)
17-
- [Installation and usage for a new project](#installation-and-usage-for-a-new-project)
18-
- [Installation and usage for an existing project](#installation-and-usage-for-an-existing-project)
19-
- [Override](#override)
20-
- [Used packages](#used-packages)
21-
- [License](#license)
17+
18+
- [Requirements](#requirements)
19+
- [Installation and usage for a new project](#installation-and-usage-for-a-new-project)
20+
- [Installation and usage for an existing project](#installation-and-usage-for-an-existing-project)
21+
- [Override](#override)
22+
- [Used packages](#used-packages)
23+
- [License](#license)
2224

2325
## Requirements
24-
* for web: `react`, for mobile: `react-native`
25-
* `node: ^16.13`
26-
* `eslint: ^8.13.0`
26+
27+
- `node: ^16.13`
28+
- `eslint: ~8.20.0`
29+
- `eslint-plugin-prettier: ^4.2.0`
2730

2831
## Installation and usage for a new project
29-
1. Install `@mobile-reality/eslint-config`, `eslint` and `prettier`:
32+
33+
1. Install `@mobile-reality/eslint-config`, `eslint`, `prettier` and `eslint-plugin-prettier`:
34+
3035
```sh
31-
yarn add -D @mobile-reality/eslint-config eslint@latest prettier@latest
36+
yarn add -D @mobile-reality/eslint-config eslint@~8.20.0 prettier eslint-plugin-prettier
3237
```
38+
3339
or
40+
3441
```sh
35-
npm i -D @mobile-reality/eslint-config eslint@latest prettier@latest
42+
npm i -D @mobile-reality/eslint-config eslint@~8.20.0 prettier eslint-plugin-prettier
3643
```
3744

3845
2. Copy `.prettierrc` from `node_modules/@mobile-reality/eslint-config` to your root directory
39-
3. Add to your root `.eslintrc.js` file and:
40-
* if you are using **React with TypeScript**:
41-
```typescript jsx
42-
module.exports = {
43-
extends: [
44-
'@mobile-reality'
45-
]
46-
};
47-
```
48-
* if you are using **React without TypeScript**:
49-
```typescript jsx
50-
module.exports = {
51-
extends: [
52-
'@mobile-reality/eslint-config/react-javascript'
53-
]
54-
};
55-
```
56-
* if you are using **React Native with TypeScript**:
57-
```typescript jsx
46+
3. Add to your root `.eslintrc.js` file:
47+
```javascript
5848
module.exports = {
49+
root: true,
50+
env: {}, // env config is based on project scope eg is it only node or node+browser
5951
extends: [
60-
'@mobile-reality/eslint-config/react-native'
61-
]
52+
'@mobile-reality/eslint-config/XXX', // base config based on project scope, XXX described below
53+
'plugin:prettier/recommended', // to include prettier rules in eslint
54+
],
55+
// if jest is used jest config should be added to overrides section
56+
overrides: [
57+
{
58+
files: ['test/**/*.test.ts'], // glob pattern has to match test files
59+
extends: ['@mobile-reality/eslint-config/configs/jest'],
60+
},
61+
],
6262
};
6363
```
64-
64+
XXX is a preconfigured eslint config for MR projects. Supported configs with required peerDependencies (which must be installed in project):
65+
- node-javascript
66+
- node-typescript (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0)
67+
- react-javascript (eslint-plugin-unicorn eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort)
68+
- react-typescript (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0 eslint-plugin-unicorn eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort)
69+
- react-native (@typescript-eslint/eslint-plugin@~5.31.0 @typescript-eslint/parser@~5.31.0 eslint-plugin-unicorn eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-simple-import-sort eslint-plugin-react-native)
70+
6571
## Installation and usage for an existing project
72+
6673
1. Remove all `ESLint` and `prettier` dependencies (e.g. `eslint`, `prettier`, `eslint-plugin-prettier`, `@typescript-eslint/eslint-plugin` etc.) from package.json
6774
2. Reinstall `node_modules` (so remove them and install with `npm i` or `yarn install`)
6875
3. Go to the [installation step](#installation-and-usage-for-a-new-project)
6976
7077
## Override
78+
7179
You can override rules by adding a rule to the rules section e.g.:
72-
```typescript jsx
73-
module.exports = {
74-
extends: [
75-
'@mobile-reality'
76-
],
77-
rules: {
78-
"no-console": "off"
79-
}
80-
};
80+
81+
```javascript
82+
module.exports = {
83+
root: true,
84+
extends: ['@mobile-reality'],
85+
rules: {
86+
'no-console': 'off',
87+
},
88+
};
8189
```
8290
8391
## Used packages
84-
* [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin)
85-
* [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser)
86-
* [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier)
87-
* [eslint-plugin-flowtype](https://github.com/gajus/eslint-plugin-flowtype)
88-
* [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest)
89-
* [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
90-
* [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier)
91-
* [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react)
92-
* [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
93-
* [eslint-plugin-react-native](https://github.com/intellicode/eslint-plugin-react-native)
94-
* [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort)
95-
* [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn)
92+
93+
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin)
94+
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser)
95+
- [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier)
96+
- [eslint-plugin-flowtype](https://github.com/gajus/eslint-plugin-flowtype)
97+
- [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest)
98+
- [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
99+
- [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react)
100+
- [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
101+
- [eslint-plugin-react-native](https://github.com/intellicode/eslint-plugin-react-native)
102+
- [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort)
103+
- [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn)
96104
97105
## License
98106

configs/react-native.js

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module.exports = {
55
'react-native/no-inline-styles': 'error',
66
'react-native/no-color-literals': 'error',
77
'react-native/no-single-element-style-arrays': 'error',
8-
'react-native/split-platform-components': 'off',
9-
'react-native/no-raw-text': 'off',
108
'@typescript-eslint/no-use-before-define': 'off',
119
'@typescript-eslint/no-require-imports': 'off',
1210
},

index.js

-3
This file was deleted.

node-javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: ['./configs/eslint', 'plugin:prettier/recommended'],
2+
extends: ['./configs/eslint', 'prettier'],
33
};

node-typescript.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module.exports = {
2-
extends: [
3-
'./configs/eslint',
4-
'./configs/typescript',
5-
'plugin:prettier/recommended',
6-
],
2+
extends: ['./configs/eslint', './configs/typescript', 'prettier'],
73
};

package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"engines": {
66
"node": "^16.13"
77
},
8-
"main": "index.js",
98
"repository": "https://github.com/MobileReality/eslint-config",
109
"author": "Mobile Reality <biuro@mobilereality.pl> (https://mobilereality.pl)",
1110
"contributors": [
@@ -35,25 +34,24 @@
3534
"mobile reality"
3635
],
3736
"scripts": {
38-
"test": "echo \"Error: no test specified\" && exit 1",
3937
"release": "release-it",
4038
"release:beta": "release-it --preRelease=beta --no-git.requireUpstream",
4139
"prepare": "husky install"
4240
},
4341
"peerDependencies": {
42+
"@typescript-eslint/eslint-plugin": "~5.31.0",
43+
"@typescript-eslint/parser": "~5.31.0",
4444
"eslint": "~8.20.0",
45-
"prettier": "^2.6.2",
46-
"@typescript-eslint/eslint-plugin": "^5.17.0",
47-
"@typescript-eslint/parser": "^5.17.0",
4845
"eslint-config-prettier": "^8.5.0",
4946
"eslint-plugin-jest": "^26.1.5",
5047
"eslint-plugin-jsx-a11y": "^6.5.1",
51-
"eslint-plugin-prettier": "^4.0.0",
48+
"eslint-plugin-prettier": "^4.2.0",
5249
"eslint-plugin-react": "^7.29.4",
5350
"eslint-plugin-react-hooks": "^4.4.0",
5451
"eslint-plugin-react-native": "^4.0.0",
5552
"eslint-plugin-simple-import-sort": "^7.0.0",
56-
"eslint-plugin-unicorn": "^42.0.0"
53+
"eslint-plugin-unicorn": "^42.0.0",
54+
"prettier": "^2.7.0"
5755
},
5856
"peerDependenciesMeta": {
5957
"@typescript-eslint/eslint-plugin": {
@@ -88,10 +86,10 @@
8886
"@release-it/conventional-changelog": "^5.0.0",
8987
"husky": "^8.0.1",
9088
"lint-staged": "^12.3.7",
91-
"prettier": "^2.6.2",
89+
"prettier": "^2.7.1",
9290
"release-it": "^15.0.0"
9391
},
9492
"lint-staged": {
95-
"*.js": "prettier --write ."
93+
"*.{md,json,js}": "prettier --write ."
9694
}
9795
}

react-javascript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module.exports = {
33
'./configs/eslint',
44
'./configs/unicorn',
55
'./configs/react',
6-
'plugin:prettier/recommended',
6+
'prettier',
77
],
88
};

react-native.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ module.exports = {
88
'./configs/unicorn',
99
'./configs/react',
1010
'./configs/react-native',
11-
'plugin:prettier/recommended',
11+
'prettier',
1212
],
1313
};

react-typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ module.exports = {
44
'./configs/typescript',
55
'./configs/unicorn',
66
'./configs/react',
7-
'plugin:prettier/recommended',
7+
'prettier',
88
],
99
};

0 commit comments

Comments
 (0)