1 | <h1 align="center">Opinionated 🙏</h1>
|
2 |
|
3 | <h3 align="center">Opinionated tooling for JavaScript & TypeScript projects.</h3>
|
4 |
|
5 | ## Why?
|
6 |
|
7 | Because orchestrating all the tools, linters, formatters, etc. in each project can took a long time
|
8 | and their configuration will differ more and more as you will copy it between multiple projects.
|
9 |
|
10 | **Opinionated** provides everything in one place and upgrading your tool chain is as easy as upgrading the dependency version.
|
11 |
|
12 | ## Installation
|
13 |
|
14 | ```
|
15 | $ yarn add @deftomat/opinionated --dev
|
16 | ```
|
17 |
|
18 | ## Usage
|
19 |
|
20 | Tool provides the following commands:
|
21 |
|
22 | ### > Pre-commit
|
23 |
|
24 | ```
|
25 | $ opinionated pre-commit
|
26 | ```
|
27 |
|
28 | Pre-commit command will try to run simple, auto-fixable operations on staged files.
|
29 | Operations includes common ESLint rules, Prettier, etc.
|
30 |
|
31 | Command is designed to be opaque and hassle free, so theoretically, pre-commit check should pass for 99% of commits without any error or warning.
|
32 |
|
33 | ### > Checkup
|
34 |
|
35 | ```
|
36 | $ opinionated checkup
|
37 | ```
|
38 |
|
39 | Checkup command allows you to keep your project in top shape.
|
40 |
|
41 | Command includes:
|
42 |
|
43 | - **Engine check** - Ensures that you are using the right NodeJS version.
|
44 | - **Integrity** - (yarn only) Ensures that dependencies are installed properly.
|
45 | - **Dependency duplicates check** - (yarn only) Ensures no unnecessary dependency duplicates. Especially useful for monorepos.
|
46 | - **Linter** - Strict ESLint rules.
|
47 | - **TypeScript check** - Detects type errors and unused code.
|
48 | - **Formatting** - Runs Prettier.
|
49 |
|
50 | Command is aware of _yarn workspaces_ and is able to run checks on whole monorepo or just in one package.
|
51 | To run checks in all packages, just run it in project's root. To run checks in one package, you need to run it in package's directory.
|
52 |
|
53 | > 💡 We recommend to run this command before pull requests and deployments.
|
54 |
|
55 | ### > Ensure configs
|
56 |
|
57 | ```
|
58 | $ opinionated ensure-configs
|
59 | ```
|
60 |
|
61 | Command will add the following configs if necessary:
|
62 |
|
63 | - [EditorConfig](https://editorconfig.org/) - Makes sure that every developer use the same indentation, charset, EOF, etc.
|
64 | - [Prettier](https://prettier.io/) - Makes sure that every supported editor use the same auto-formatting rules.
|
65 | - [.nvmrc](https://github.com/nvm-sh/nvm) - Allows to automatically switch to the correct NodeJS version by running `nvm use` command in project's directory.
|
66 |
|
67 | > 💡 This command is usually not necessary as every other command runs it by default.
|
68 |
|
69 | ## Integration into project
|
70 |
|
71 | To integrate the tool into your project, we recommend the following `packages.json`:
|
72 |
|
73 | ```
|
74 | {
|
75 | ...
|
76 | "scripts": {
|
77 | "checkup": "opinionated checkup"
|
78 | },
|
79 | "husky": {
|
80 | "hooks": {
|
81 | "pre-commit": "opinionated pre-commit"
|
82 | }
|
83 | },
|
84 | "devDependencies": {
|
85 | "@deftomat/opinionated": "^0.6.0",
|
86 | "husky": "^4.0.0"
|
87 | }
|
88 | ...
|
89 | }
|
90 | ```
|
91 |
|
92 | This configuration allows you to automatically run _pre-commit_ check before each commit (via [Husky](https://github.com/typicode/husky) git hook) and provides `yarn checkup` to easily run _checkup_ command.
|
93 |
|
94 | ## Custom ESLint rules
|
95 |
|
96 | If you need to alter the predefined ESLint rules, just follow the [ESLint configuration guide](https://eslint.org/docs/user-guide/configuring).
|
97 |
|
98 | Any rule specified in your configuration file will be merged over build-in configuration. This allows you to add/edit/remove any rule you want.
|
99 |
|
100 | ## Ignoring files and directories
|
101 |
|
102 | As tool is using ESLint and Prettier, you can follow their guidelines to ignore any file or directory.
|
103 |
|
104 | However, when tool detects, that there are no _.ignore_ file for these tools, then it tries to use `.opinionatedignore`
|
105 | file which will be applied to both ESLint and Prettier. If there is no `.opinionatedignore`, then `.gitignore` will be used.
|
106 |
|
107 | **Resolution order for ESLint:**
|
108 |
|
109 | - `.eslintignore`
|
110 | - `eslintIgnore` property in `package.json`
|
111 | - `.opinionatedignore`
|
112 | - `.gitignore`
|
113 |
|
114 | **Resolution order for Prettier:**
|
115 |
|
116 | - `.prettierignore`
|
117 | - `.opinionatedignore`
|
118 | - `.gitignore`
|