Skip to content

Commit

Permalink
feat(codequality): code quality setup
Browse files Browse the repository at this point in the history
Configured linters, code formatters and git pre commit hooks.
Added release and changelog plugins.

Installed dependencies:
```shell
# Eslint prettier
yarn add --dev --exact eslint-plugin-jest@latest eslint-config-prettier eslint-plugin-prettier  eslint-plugin-import@latest
yarn add --dev --exact eslint-plugin-react@latest  eslint-plugin-jsx-a11y@latest
yarn add --dev --exact eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-airbnb
yarn add --dev --exact prettier lint-staged

# Install commitlint cli and conventional config
yarn add --dev --exact @commitlint/config-conventional @commitlint/cli
# Configure commitlint to use conventional config
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js

# Release notes
yarn add --dev --exact standard-version
```
  • Loading branch information
rbiedrawa committed Mar 14, 2022
1 parent d018b0e commit 6559f19
Show file tree
Hide file tree
Showing 36 changed files with 2,049 additions and 590 deletions.
66 changes: 66 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module.exports = {
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier", "react", "import"],
env: {
browser: true,
jest: true,
es2021: true,
node: true,
},
"extends": [
'airbnb-base',
"airbnb-typescript",
'prettier',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
],
settings: {
react: {
pragma: 'React',
version: 'detect',
"fragment": "Fragment",
},
'import/resolver': {
node: {
extensions: ['.tsx', '.ts', '.js', '.json'],
},
alias: [
['src', './src'],
],
},
},
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
"react/function-component-definition": [
2,
{
namedComponents: "arrow-function",
unnamedComponents: "arrow-function",
},
],
"react/react-in-jsx-scope": "off",
"no-param-reassign": 0,
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "error"
},
parserOptions: {
sourceType: 'module',
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
},
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# project
TODO.md
.husky

# ide
*.iml
Expand Down
20 changes: 20 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**/*.png
**/*.svg
**/*.ico
package.json
lib/
es/
dist/
.next/
coverage/
LICENSE
yarn.lock
yarn-error.log
*.sh
.gitignore
.npmignore
.prettierignore
.DS_Store
.editorconfig
.eslintignore
**/*.yml
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"singleQuote": true,
"tabWidth": 2,
"endOfLine": "lf",
"trailingComma": "all",
"printWidth": 100,
"arrowParens": "avoid",
"bracketSpacing": true,
"semi": false,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
}
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.


## Code Quality

### ESLint and Prettier

Running the script `yarn format` will format the code style of all TypeScript files.

The script `yarn lint` will run linter in the project.
If any best practices, standards, or code styles are not meet in code, it will display the actual error or warning.

Run `yarn lint:fix` command to fix automatically any error found (if the linter knows how to fix it😉) and format code.

### Commit hooks

Enforce code conventions and prevent bad commits with Husky pre-commit hook.

To install and configure Husky, run:
```shell
npx husky install
```

To automatically run linter on staged files, run below command to install pre commit hook.

```shell
npx husky add .husky/pre-commit "yarn lint-staged"
```

To enforce conventional commit format on git messages, run below command to use commitlint.
```shell
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
```


## Release

[//]: # (TODO: add readme for release via Standard Version)


## References

* [React documentation](https://reactjs.org/)
Expand All @@ -48,6 +86,11 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d
* [Redux Logger](https://github.com/LogRocket/redux-logger)
* [I18next](https://react.i18next.com/)
* [JSON Server](https://github.com/typicode/json-server)
* [ESLint](https://eslint.org/)
* [Prettier](https://prettier.io/)
* [Husky](https://typicode.github.io/husky/#/)
* [commitlint](https://commitlint.js.org/#/) - Lint commit messages
* [Standard Version](https://github.com/conventional-changelog/standard-version) - A utility for versioning using semver and CHANGELOG generation powered by Conventional Commits.

## Additional Links

Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']}
39 changes: 37 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@hookform/resolvers": "^2.8.8",
"@mui/icons-material": "^5.5.0",
"@mui/material": "^5.5.0",
"@redux-saga/core": "^1.1.3",
"@reduxjs/toolkit": "^1.8.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
Expand All @@ -17,6 +18,7 @@
"@types/react": "^17.0.20",
"@types/react-dom": "^17.0.9",
"@types/redux-logger": "^3.0.9",
"history": "^5.3.0",
"i18next": "^21.6.14",
"json-server": "^0.17.0",
"react": "^17.0.2",
Expand All @@ -36,10 +38,18 @@
},
"scripts": {
"start": "react-scripts start",
"start:server": "json-server --watch db.json --port 8000",
"start:backend": "json-server --watch db.json --port 8000",
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "react-scripts test",
"eject": "react-scripts eject"
"coverage": "react-scripts test --coverage",
"format": "prettier --write 'src'",
"eslint": "eslint --ext ts,tsx",
"lint": "yarn eslint src",
"lint:fix": "yarn lint --fix",
"release": "standard-version --no-verify",
"release:first-release": "standard-version --first-release --no-verify",
"release:dry-run": "standard-version --dry-run --no-verify"
},
"eslintConfig": {
"extends": [
Expand All @@ -58,5 +68,30 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@commitlint/cli": "16.2.1",
"@commitlint/config-conventional": "16.2.1",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
"eslint": "8.11.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "16.1.2",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-jest": "26.1.1",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "^7.29.3",
"eslint-plugin-react-hooks": "4.3.0",
"lint-staged": "12.3.5",
"prettier": "2.5.1",
"standard-version": "9.3.2"
},
"lint-staged": {
"src/**/*.ts": [
"prettier --write",
"eslint --fix"
]
}
}
31 changes: 15 additions & 16 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React from "react";
import {Provider} from "react-redux";

import './App.css';
import {history, store} from "./store/store";
import AppRoutes from "./routes";
import {HistoryRouter as Router} from "redux-first-history/rr6";
import React from 'react'
import {Provider} from 'react-redux'

import './App.css'
import {HistoryRouter as Router} from 'redux-first-history/rr6'
import {history, store} from './store/store'
import AppRoutes from './routes'

const App = () => (
<>
<Provider store={store}>
<Router history={history}>
<AppRoutes/>
</Router>
</Provider>
</>
);
<>
<Provider store={store}>
<Router history={history}>
<AppRoutes/>
</Router>
</Provider>
</>
)

export default App;
export default App
Loading

0 comments on commit 6559f19

Please sign in to comment.