Skip to content

Commit 638a222

Browse files
committed
add ESLint, Prettier, pre-commit hooks (Husky)
1 parent 4dc260e commit 638a222

9 files changed

Lines changed: 89 additions & 12 deletions

File tree

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules/
2+
package-lock.json
3+
.env
4+
/coverage/
5+
build/
6+
bin/

.eslintrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
ecmaVersion: 2020,
5+
sourceType: 'module',
6+
ecmaFeatures: {
7+
jsx: true
8+
}
9+
},
10+
settings: {
11+
react: {
12+
version: 'detect'
13+
}
14+
},
15+
env: {
16+
jest: true,
17+
browser: true,
18+
amd: true,
19+
node: true
20+
},
21+
extends: [
22+
'eslint:recommended',
23+
'plugin:react/recommended',
24+
'plugin:prettier/recommended' // Make this the last element so prettier config overrides other formatting rules
25+
],
26+
rules: {
27+
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
28+
'prettier/prettier': ['error', {}, { usePrettierrc: true }]
29+
}
30+
}

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.env
2+
/coverage/
3+
public/
4+
node_modules/
5+
internals/generators/
6+
bin/
7+
package-lock.json
8+
package.json

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "all"
8+
}

package.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"test:watch": "jest --watch",
1717
"test:coverage": "jest --coverage",
1818
"presetup": "npm i shelljs compare-versions",
19-
"setup": "node ./bin/setup.js"
19+
"setup": "node ./bin/setup.js",
20+
"lint": "eslint --fix src/**/*.js",
21+
"format": "prettier src/**/*.js --write --config ./.prettierrc"
2022
},
2123
"keywords": [],
2224
"author": "",
@@ -30,11 +32,19 @@
3032
"@testing-library/user-event": "^12.6.3",
3133
"babel-loader": "^8.2.2",
3234
"css-loader": "^5.0.1",
35+
"eslint": "^7.19.0",
36+
"eslint-config-prettier": "^7.2.0",
37+
"eslint-plugin-prettier": "^3.3.1",
38+
"eslint-plugin-react": "^7.22.0",
39+
"eslint-plugin-react-hooks": "^4.2.0",
40+
"husky": "^4.3.8",
3341
"jest": "^26.6.3",
3442
"jest-dom": "^4.0.0",
43+
"lint-staged": "^10.5.3",
3544
"mini-css-extract-plugin": "^1.3.5",
3645
"node-fetch": "^2.6.1",
3746
"node-sass": "^5.0.0",
47+
"prettier": "^2.2.1",
3848
"sass-loader": "^10.1.1",
3949
"style-loader": "^2.0.0",
4050
"webpack": "^5.19.0",
@@ -45,6 +55,15 @@
4555
"npm": ">=5",
4656
"node": ">=8.15.1"
4757
},
58+
"husky": {
59+
"hooks": {
60+
"pre-commit": "npm run lint && npm run format"
61+
}
62+
},
63+
"lint-staged": {
64+
"*.+(js|jsx)": ["eslint --fix", "git add"],
65+
"*.+(json|css|md)": ["prettier --write", "git add"]
66+
},
4867
"dependencies": {
4968
"compare-versions": "^3.6.0",
5069
"dotenv": "^8.2.0",

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Jest/React Testing Library<br>
99
Env Files<br>
1010
PropTypes<br>
1111

12+
## Setup
13+
14+
Run `git clone https://github.com/ilyasudakov/basic-react-boilerplate.git` to clone repository<br>
15+
Run `npm run setup` to initiate setup process, where you can create new repo if you want to<br>
16+
Then you can `npm run start` to view template app
17+
1218
## Commands
1319

1420
Run `npm i` to install all dependencies<br>

src/components/App.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from "react";
2-
import { render } from "@testing-library/react";
3-
import App from "./App.jsx";
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import App from './App.jsx';
44

5-
describe("App component", () => {
6-
test("renders", () => {
5+
describe('App component', () => {
6+
test('renders', () => {
77
const { getByText } = render(<App />);
8-
expect(getByText("App")).toBeInTheDocument();
8+
expect(getByText('App')).toBeInTheDocument();
99
});
1010
});

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from "react";
2-
import ReactDOM from "react-dom";
3-
import App from "./components/App.jsx";
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './components/App.jsx';
44

5-
ReactDOM.render(<App />, document.getElementById("root"));
5+
ReactDOM.render(<App />, document.getElementById('root'));

src/setupTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import "@testing-library/jest-dom/extend-expect";
1+
import '@testing-library/jest-dom/extend-expect';

0 commit comments

Comments
 (0)