You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+96-8Lines changed: 96 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,33 @@
1
1
# EOX ESLint & Prettier config for JS projects
2
+
3
+
## About
4
+
5
+
This reusable config aims to be our default way of setting up linting and formatting for JS projects. It includes:
6
+
7
+
- eslint dependency
8
+
- prettier dependency
9
+
- typescript dependency
10
+
- recommended eslint config
11
+
- recommended typescript-eslint
12
+
- typescript-eslint parser
13
+
- vue-eslint parser
14
+
- cypress rules
15
+
- chai friendly errors
16
+
17
+
The config also includes a minimal set of rules, defined in [index.js](./index.js).
18
+
2
19
## Installation
20
+
3
21
```js
4
22
npm install --save-dev @eox/eslint-config
5
23
```
24
+
6
25
## Usage
26
+
7
27
### Prettier
28
+
8
29
To run prettier and format all your files in the current folder, use
30
+
9
31
```bash
10
32
npx prettier --write .
11
33
or
@@ -15,23 +37,50 @@ npx prettier --write "**/*"
15
37
Please refer to the [Prettier CLI docs](https://prettier.io/docs/en/cli.html) for further details.
16
38
17
39
### ESLint
18
-
To include ESLint in the project, create a file called `.eslintrc.js` in the app root:
40
+
41
+
To include ESLint in the project, create a file called `eslint.config.mjs` in the app root:
42
+
19
43
```js
20
-
module.exports= {
21
-
extends:"@eox"
22
-
}
44
+
importeoxfrom"@eox/eslint-config";
45
+
46
+
exportdefault [...eox];
23
47
```
48
+
24
49
Finally, to run ESLint with auto-fixing, use
50
+
25
51
```bash
26
-
npx eslint .--fix
52
+
npx eslint --fix.
27
53
```
28
54
29
-
Please refer to the [ESLint CLI docs](https://eslint.org/docs/latest/user-guide/command-line-interface) for further details.
55
+
Please refer to the [ESLint configuration docs](https://eslint.org/docs/latest/use/configure/) and [ESLint CLI docs](https://eslint.org/docs/latest/user-guide/command-line-interface) for further details.
56
+
57
+
### TypeScript
58
+
59
+
To use typescript checks, create a `tsconfig.json` in the project root
60
+
61
+
```json
62
+
{
63
+
"compilerOptions": {
64
+
"allowJs": true,
65
+
"checkJs": true,
66
+
...
67
+
}
68
+
}
69
+
```
70
+
71
+
and run the check with
72
+
73
+
```bash
74
+
npx tsc
75
+
```
30
76
31
77
## Ignoring files
32
-
You can add [.eslintignore](https://eslint.org/docs/latest/user-guide/configuring/ignoring-code) and [.prettierignore](https://prettier.io/docs/en/ignore.html) files to ignore certain folders or files/patterns.
33
78
34
-
Both ignore files should ideally have the same content, e.g.:
79
+
not any longer -> only for prettier?
80
+
81
+
You can add a [.prettierignore](https://prettier.io/docs/en/ignore.html) file to ignore certain folders or files/patterns.
82
+
83
+
E.g.:
35
84
36
85
```
37
86
public
@@ -42,32 +91,71 @@ dist
42
91
# adapt according to your project needs
43
92
```
44
93
94
+
For ESlint, use the [`ignores` property in the config file](https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files). Example:
95
+
96
+
```js
97
+
// other config
98
+
{ ignores: ["dist"] },
99
+
// other config
100
+
```
101
+
45
102
## Custom configuration & rules
103
+
46
104
Both Prettier and ESLint allow for some rule customization. Please check the [Prettier configuration options](https://prettier.io/docs/en/options.html) and the [ESLint rules](https://eslint.org/docs/rules/) for an explanation of rules that could be added/modified to this file for individual projects.
47
105
48
106
BUT: please consider if this is really necessary, or if it could be included in the centralized config rather than in an individual project. Ideally, the individual projects should not use any custom rules.
To check if your code is valid before committing or inside a CI pipeline, use
133
+
52
134
```bash
53
135
npx prettier --check .
54
136
npx eslint .
55
137
```
56
138
57
139
## Automation in VS Code (extension, settings)
140
+
58
141
### Prettier
142
+
59
143
Although you can use prettier via command line, in a pre-commit hook or in a CI pipeline, you can also use the VS Code extension to format files (or file sections) via a handy command or even automatically (e.g. on file save) right inside your code editor.
0 commit comments