@@ -8,9 +8,54 @@ Linting and formatting configuration shared by Netlify Node.js repositories:
8
8
- [ Editorconfig] ( https://editorconfig.org/ )
9
9
- ` .gitattributes `
10
10
11
- To add to a new Node.js repository, please check an existing Netlify Node.js repository and copy its:
11
+ ## How to add to a new Node.js repository
12
12
13
- - ` .eslintrc.js `
14
- - ` .prettierrc.json `
15
- - ` .editorconfig `
16
- - ` .gitattributes `
13
+ - ` npm install -D @netlify/eslint-config-node husky cross-env npm-run-all `
14
+ - Add the following ` .eslintrc.js ` to the root of the project. Individual ` rules ` and ` overrides ` can be tweaked for the
15
+ specific project.
16
+
17
+ ``` js
18
+ const { overrides } = require (' @netlify/eslint-config-node' )
19
+
20
+ module .exports = {
21
+ extends: ' @netlify/eslint-config-node' ,
22
+ rules: {},
23
+ overrides: [... overrides],
24
+ }
25
+ ```
26
+
27
+ - Add the following ` .prettierrc.json ` to the root of the project:
28
+
29
+ ``` json
30
+ " @netlify/eslint-config-node/.prettierrc.json"
31
+ ```
32
+
33
+ - Copy the ` .editorconfig ` ,` .gitattributes ` and ` ./scripts/run_on_error.js ` files relativity to the root of the project.
34
+ - Add the following properties to the ` package.json ` . Please replace the ` scriptsArgs ` globbing expressions to match the
35
+ files where the source JavaScript/Markdown/HTML/JSON/YAML files are located. ` npm run format ` should also be run
36
+ during ` npm test ` and ` npm run format:ci ` during CI
37
+ ([ example] ( https://github.com/netlify/cli/blob/master/.github/workflows/main.yml ) ).
38
+
39
+ ``` json
40
+ {
41
+ "scripts" : {
42
+ "format" : " run-s format:check-fix:*" ,
43
+ "format:ci" : " run-s format:check:*" ,
44
+ "format:check-fix:lint" : " ./scripts/run_on_error.js format:check:lint format:fix:lint" ,
45
+ "format:check:lint" : " cross-env-shell eslint $npm_package_scriptsArgs_eslint" ,
46
+ "format:fix:lint" : " cross-env-shell eslint --fix $npm_package_scriptsArgs_eslint" ,
47
+ "format:check-fix:prettier" : " ./scripts/run_on_error.js format:check:prettier format:fix:prettier" ,
48
+ "format:check:prettier" : " cross-env-shell prettier --check $npm_package_scriptsArgs_prettier" ,
49
+ "format:fix:prettier" : " cross-env-shell prettier --write $npm_package_scriptsArgs_prettier"
50
+ },
51
+ "scriptsArgs" : {
52
+ "eslint" : " --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \" {src,scripts,site,tests,.github}/**/*.{js,md,html}\" \" *.{js,md,html}\" \" .*.{js,md,html}\" " ,
53
+ "prettier" : " --ignore-path .gitignore --loglevel=warn \" {src,scripts,site,tests,.github}/**/*.{js,md,yml,json,html}\" \" *.{js,yml,json,html}\" \" .*.{js,yml,json,html}\" \" !package-lock.json\" "
54
+ },
55
+ "husky" : {
56
+ "hooks" : {
57
+ "pre-push" : " npm run format"
58
+ }
59
+ }
60
+ }
61
+ ```
0 commit comments