Skip to content

Commit 09b8423

Browse files
authored
chore: setup eslint & prettier (#3)
## Description - Configuration for `eslint` and `prettier` for lint and format - Add pre-commit hook with `lint-staged` ## Checklist before requesting a review - [x] I have conducted a self-review of my code. - [x] I have conducted a QA.
1 parent e8c0957 commit 09b8423

13 files changed

+3571
-913
lines changed

.eslintrc.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** @type {import('eslint').Linter.Config} */
2+
module.exports = {
3+
parser: "@typescript-eslint/parser",
4+
parserOptions: {
5+
project: "tsconfig.json",
6+
tsconfigRootDir: __dirname,
7+
sourceType: "module",
8+
},
9+
plugins: ["@typescript-eslint/eslint-plugin"],
10+
extends: ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
11+
root: true,
12+
env: {
13+
node: true,
14+
jest: true,
15+
},
16+
ignorePatterns: [".eslintrc.js"],
17+
rules: {
18+
"@typescript-eslint/explicit-function-return-type": "error",
19+
"@typescript-eslint/explicit-module-boundary-types": "error",
20+
"@typescript-eslint/no-misused-promises": "error",
21+
"@typescript-eslint/no-floating-promises": "error",
22+
"@typescript-eslint/no-explicit-any": "error",
23+
"@typescript-eslint/no-unsafe-assignment": "warn",
24+
"@typescript-eslint/no-unsafe-argument": "warn",
25+
"@typescript-eslint/no-unsafe-member-access": "error",
26+
"@typescript-eslint/no-unsafe-return": "error",
27+
"@typescript-eslint/no-unused-vars": [
28+
"error",
29+
{ argsIgnorePattern: "_+", ignoreRestSiblings: true },
30+
],
31+
"@typescript-eslint/prefer-as-const": "warn",
32+
},
33+
};

.github/actions/setup/action.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: "Setup environment"
22
description: "Prepare repository and all dependencies"
33

44
runs:
5-
using: "composite"
6-
steps:
7-
- name: Use pnpm
8-
uses: pnpm/action-setup@v4
9-
with:
10-
run_install: false
5+
using: "composite"
6+
steps:
7+
- name: Use pnpm
8+
uses: pnpm/action-setup@v4
9+
with:
10+
run_install: false
1111

12-
- name: Use Node
13-
uses: actions/setup-node@v4
14-
with:
15-
node-version: 20
16-
cache: "pnpm"
12+
- name: Use Node
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
cache: "pnpm"

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 1
16-
16+
1717
- name: Setup environment
1818
uses: ./.github/actions/setup
19-
19+
2020
- name: Install dependencies
2121
run: pnpm install --frozen-lockfile
2222

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Setup environment
2626
uses: ./.github/actions/setup
27-
27+
2828
- name: Install dependencies
2929
run: pnpm install --frozen-lockfile
3030

.github/workflows/test-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- name: Setup environment
1717
uses: ./.github/actions/setup
18-
18+
1919
- name: Install dependencies
2020
run: pnpm install --frozen-lockfile
2121

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- name: Setup environment
1717
uses: ./.github/actions/setup
18-
18+
1919
- name: Install dependencies
2020
run: pnpm install --frozen-lockfile
2121

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm lint-staged && pnpm check-types

.prettierrc

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"arrowParens": "always",
3+
"printWidth": 100,
4+
"singleQuote": false,
5+
"semi": true,
6+
"trailingComma": "all",
7+
"tabWidth": 4,
8+
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
9+
"importOrder": [
10+
"<TYPES>",
11+
"<THIRD_PARTY_MODULES>",
12+
"",
13+
"<TYPES>^[.|..|~]",
14+
"^~/",
15+
"^[../]",
16+
"^[./]"
17+
],
18+
"importOrderParserPlugins": ["typescript", "decorators-legacy"],
19+
"importOrderTypeScriptVersion": "5.4.5"
20+
}

README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,40 @@
22

33
## Features
44

5+
### Lint and format
6+
7+
Use ESLint and Prettier to easily find issues as you code
8+
59
### Github workflows CI
10+
611
Lint code and check commit messages format on every push.
712

813
Run all tests and see the coverage before merging changes.
914

10-
1115
## Tech stack
12-
- [pnpm](https://pnpm.io/): package and workspace manager
13-
- [turborepo](https://turbo.build/repo/docs): for managing the monorepo and the build system
16+
17+
- [pnpm](https://pnpm.io/): package and workspace manager
18+
- [turborepo](https://turbo.build/repo/docs): for managing the monorepo and the build system
19+
20+
### Configuring Prettier sort import plugin
21+
22+
You can further add sorting rules for your monorepo, for example in `.prettierrc` you can add:
23+
24+
```json
25+
...
26+
"importOrder": [
27+
"<TYPES>",
28+
...
29+
"",
30+
"<TYPES>^@myproject", //added
31+
"^@myproject/(.*)$", //added
32+
"",
33+
...
34+
],
35+
...
36+
```
37+
38+
We use [IanVs prettier-plugin-sort-imports](https://github.com/IanVS/prettier-plugin-sort-imports)
1439

1540
## Contributing
1641

package.json

+48-34
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
{
2-
"name": "ts-turborepo-boilerplate",
3-
"version": "0.0.1",
4-
"description": "",
5-
"author": "Wonderland",
6-
"private": true,
7-
"license": "MIT",
8-
"type": "module",
9-
"engines": {
10-
"node": "20"
11-
},
12-
"scripts": {
13-
"build": "turbo run build",
14-
"start": "turbo run start",
15-
"dev": "turbo run dev",
16-
"lint": "turbo run lint",
17-
"lint:fix": "turbo run lint:fix",
18-
"format": "turbo run format",
19-
"format:fix": "turbo run format:fix",
20-
"check-types": "turbo run check-types",
21-
"test": "turbo run test",
22-
"test:cov": "turbo run test:cov",
23-
"test:integration": "turbo run test:integration",
24-
"prepare": "husky",
25-
"preinstall": "npx only-allow pnpm"
26-
},
27-
"packageManager": "[email protected]+sha256.46f1bbc8f8020aa9869568c387198f1a813f21fb44c82f400e7d1dbde6c70b40",
28-
"devDependencies": {
29-
"@commitlint/config-conventional": "19.4.1",
30-
"@types/node": "22.5.4",
31-
"commitlint": "19.4.1",
32-
"husky": "9.1.5",
33-
"turbo": "2.1.1",
34-
"typescript": "5.5.4"
35-
}
2+
"name": "ts-turborepo-boilerplate",
3+
"version": "0.0.1",
4+
"private": true,
5+
"description": "",
6+
"license": "MIT",
7+
"author": "Wonderland",
8+
"type": "module",
9+
"scripts": {
10+
"build": "turbo run build",
11+
"check-types": "turbo run check-types",
12+
"dev": "turbo run dev",
13+
"format": "turbo run format",
14+
"format:fix": "turbo run format:fix",
15+
"preinstall": "npx only-allow pnpm",
16+
"lint": "turbo run lint",
17+
"lint:fix": "turbo run lint:fix",
18+
"prepare": "husky",
19+
"start": "turbo run start",
20+
"test": "turbo run test",
21+
"test:cov": "turbo run test:cov",
22+
"test:integration": "turbo run test:integration"
23+
},
24+
"lint-staged": {
25+
"*": "prettier --write --ignore-unknown",
26+
"*.js,*.ts,*.json": "eslint --fix",
27+
"package.json": "sort-package-json"
28+
},
29+
"devDependencies": {
30+
"@commitlint/config-conventional": "19.4.1",
31+
"@ianvs/prettier-plugin-sort-imports": "4.3.1",
32+
"@types/node": "22.5.4",
33+
"@typescript-eslint/eslint-plugin": "7.18.0",
34+
"@typescript-eslint/parser": "7.18.0",
35+
"commitlint": "19.4.1",
36+
"eslint": "8.56.0",
37+
"eslint-config-prettier": "9.1.0",
38+
"eslint-plugin-prettier": "5.2.1",
39+
"husky": "9.1.5",
40+
"lint-staged": "15.2.10",
41+
"prettier": "3.3.3",
42+
"sort-package-json": "2.10.1",
43+
"turbo": "2.1.1",
44+
"typescript": "5.5.4"
45+
},
46+
"packageManager": "[email protected]+sha256.46f1bbc8f8020aa9869568c387198f1a813f21fb44c82f400e7d1dbde6c70b40",
47+
"engines": {
48+
"node": "20"
49+
}
3650
}

0 commit comments

Comments
 (0)