├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .prettierignore ├── .prettierrc.json ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.test.tsx ├── App.tsx ├── Child.tsx ├── assests │ ├── fonts │ │ ├── Poppins-Medium.ttf │ │ ├── Poppins-Regular.ttf │ │ └── Poppins-SemiBold.ttf │ └── images │ │ └── FaSun.png ├── index.css ├── index.tsx ├── react-app-env.d.ts ├── reportWebVitals.ts └── setupTests.ts ├── tsconfig.json └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | src/service-worker.ts 2 | src/serviceWorkerRegistration.ts -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es2021: true, 5 | jest: true, 6 | }, 7 | extends: [ 8 | "plugin:react/recommended", 9 | "airbnb", 10 | "prettier", 11 | "plugin:import/typescript", 12 | ], 13 | parser: "@typescript-eslint/parser", 14 | parserOptions: { 15 | ecmaFeatures: { 16 | jsx: true, 17 | }, 18 | ecmaVersion: 13, 19 | sourceType: "module", 20 | }, 21 | plugins: ["react", "@typescript-eslint", "security"], 22 | rules: { 23 | "import/extensions": [ 24 | "error", 25 | "ignorePackages", 26 | { ts: "never", tsx: "never" }, 27 | ], 28 | "no-use-before-define": "off", 29 | "@typescript-eslint/no-use-before-define": "error", 30 | "react/react-in-jsx-scope": "off", 31 | "react/jsx-filename-extension": ["error", { extensions: [".tsx"] }], 32 | "arrow-body-style": ["error", "always"], 33 | "react/function-component-definition": [ 34 | 2, 35 | { 36 | namedComponents: "arrow-function", 37 | unnamedComponents: "arrow-function", 38 | }, 39 | ], 40 | }, 41 | }; 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | .eslintcache 11 | 12 | # production 13 | /build 14 | 6 15 | 16 | # misc 17 | .DS_Store 18 | .env 19 | .env.local 20 | .env.development.local 21 | .env.test.local 22 | .env.production.local 23 | 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | yarn run format:fix 6 | yarn run validate 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | src/service-worker.ts 2 | src/serviceWorkerRegistration.ts -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSameLine": false, 4 | "bracketSpacing": true, 5 | "embeddedLanguageFormatting": "auto", 6 | "htmlWhitespaceSensitivity": "css", 7 | "insertPragma": false, 8 | "jsxSingleQuote": false, 9 | "printWidth": 80, 10 | "proseWrap": "preserve", 11 | "quoteProps": "as-needed", 12 | "requirePragma": false, 13 | "semi": true, 14 | "singleQuote": false, 15 | "tabWidth": 2, 16 | "trailingComma": "es5", 17 | "useTabs": false, 18 | "vueIndentScriptAndStyle": false 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## A react-typescript boilerplate including 2 | 3 | - `prettier` 4 | - `eslint` 5 | - `lint-staged` 6 | - `husky` 7 | 8 | #  9 | 10 | [Docs](https://react-typescript-cheatsheet.netlify.app/docs/basic/setup/) 11 | 12 | - TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. 13 | - Also a powerful compiler tool which converts typescript to javascript 14 | - It also adds feature of idetifying errors at compile time rather than scratching our head at runtime🥲 15 | 16 | #  17 | 18 | [Docs](https://prettier.io/) 19 | 20 | - An Code formatter 21 | - Supports many languages 22 | - Generate prettier rules [here](https://prettier.io/playground/) 23 | 24 | #  25 | 26 | [Docs](https://eslint.org/) 27 | 28 | - Find and fix problems in your JavaScript code making code more consistent. 29 | - We already have `eslint` as an inner-dependency from react-scripts 30 | - To init eslint config run & choose options accordingly 31 | 32 | ``` 33 | npx eslint --init 34 | ``` 35 | 36 | 38 | 39 | #  40 | 41 | [Docs](https://www.npmjs.com/package/lint-staged) 42 | 43 | - Linting makes more sense when run before committing your code. By doing so you can ensure no errors go into the repository and enforce code style. 44 | 45 | #  46 | 47 | [Docs](https://www.npmjs.com/package/husky) 48 | 49 | - Whenever we inti Git in our project, it automatically comes with features called hooks. 50 | - hooks ex: `pre-commit`, `pre-push`, etc. 51 | - If we want to ensure before we actually create a commit using the `git commit`, that our code was properly `linted` and `formatted`, we could write a `pre-commit` Git hook. 52 | 53 | #  54 | 55 | 1. Clone / Download [this](https://github.com/ShubhamSj07/react-typescript-boilerplate) repo. 56 | 2. Inside the project open a terminal and run: 57 | 58 | ``` 59 | yarn install 60 | ``` 61 | 62 | This will install all the project dependencies. 63 | 64 | 3. To start the development server run: 65 | 66 | ``` 67 | yarn start 68 | ``` 69 | 70 | 4. Prettier commands 71 | 72 | - Run the below command to get a list of all unformatted code in the project. 73 | 74 | ``` 75 | yarn run format:check 76 | ``` 77 | 78 | - Run the below command to fix the unformatted code! 79 | 80 | ``` 81 | yarn run format:fix 82 | ``` 83 | 84 | 5. Eslint commands 85 | 86 | - We can run the below script present in package.json 87 | 88 | ``` 89 | yarn run lint 90 | ``` 91 | 92 | 6. Run parallel commands at once using [concurrently](https://www.npmjs.com/package/concurrently) 93 | 94 | - #### Syntax 95 | 96 | ``` 97 | concurrently \"yarn 1st-cmd\" \"yarn run 2st-cmd\" \"yarn run nth-cmd\"" 98 | ``` 99 | 100 | 7. Another great thing about lint-staged is that it automatically does the git add on the modified files. So, if we are doing prettier — write or eslint — fix, we don't have to stage the changes manually. 101 | 102 | - #### We do format:fix & run our validate script on the staged files 103 | 104 | - #### After `git add .` and `git commit -m "message"` 105 | 106 | the lint-staged kicks in and runs🚀 107 | 108 | #  109 | 110 | [](https://twitter.com/shubhamsj077) 111 | 112 | [](https://www.linkedin.com/in/shubham-jadhav-77a588192/) 113 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-typescript-boilerplate", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.14.1", 7 | "@testing-library/react": "^12.0.0", 8 | "@testing-library/user-event": "^13.2.1", 9 | "@types/jest": "^27.0.1", 10 | "@types/node": "^16.7.13", 11 | "@types/react": "^17.0.20", 12 | "@types/react-dom": "^17.0.9", 13 | "concurrently": "^7.0.0", 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-scripts": "5.0.0", 17 | "typescript": "^4.4.2", 18 | "web-vitals": "^2.1.0" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject", 25 | "prettier": "prettier . --ignore-path .gitignore", 26 | "format:check": "prettier . --ignore-path .gitignore --check", 27 | "format:fix": "prettier . --ignore-path .gitignore --write", 28 | "lint": "eslint --ext .tsx,.ts .", 29 | "validate": "concurrently \"yarn run lint\" \"yarn run type:check\" \"yarn run format:check\"", 30 | "type:check": "tsc", 31 | "prepare": "husky install" 32 | }, 33 | "eslintConfig": { 34 | "extends": [ 35 | "react-app", 36 | "react-app/jest" 37 | ] 38 | }, 39 | "browserslist": { 40 | "production": [ 41 | ">0.2%", 42 | "not dead", 43 | "not op_mini all" 44 | ], 45 | "development": [ 46 | "last 1 chrome version", 47 | "last 1 firefox version", 48 | "last 1 safari version" 49 | ] 50 | }, 51 | "devDependencies": { 52 | "@typescript-eslint/eslint-plugin": "^5.9.0", 53 | "@typescript-eslint/parser": "^5.9.0", 54 | "eslint": "^8.6.0", 55 | "eslint-config-airbnb": "^19.0.4", 56 | "eslint-config-prettier": "^8.3.0", 57 | "eslint-plugin-import": "^2.25.4", 58 | "eslint-plugin-jsx-a11y": "^6.5.1", 59 | "eslint-plugin-react": "^7.28.0", 60 | "eslint-plugin-react-hooks": "^4.3.0", 61 | "eslint-plugin-security": "^1.4.0", 62 | "husky": "^7.0.4", 63 | "lint-staged": "^12.1.5", 64 | "prettier": "^2.5.1" 65 | }, 66 | "lint-staged": { 67 | "*.{tsx,ts}": "eslint --fix", 68 | "*.{js,css,md}": "prettier --write" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShubhamSj07/react-typescript-boilerplate/948a17d7c7a9836141f4659dc684c15b392653a6/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 |