@deftomat/opinionated
v1.1.3
Published
Opinionated tooling for JavaScript & TypeScript projects.
Downloads
286
Maintainers
Readme
Why?
Because orchestrating all the tools, linters, formatters, etc. in each project can took a long time and their configuration will differ more and more as you will copy it between multiple projects.
Opinionated provides everything in one place and upgrading your tool chain is as easy as upgrading the dependency version.
Installation
$ yarn add @deftomat/opinionated --dev
or
$ npm install @deftomat/opinionated --include=dev
Usage
Tool provides the following commands:
> Pre-commit
$ opinionated pre-commit
Pre-commit command will try to run simple, auto-fixable operations on staged files. Operations includes common ESLint rules, Prettier, etc.
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.
> Checkup
$ opinionated checkup
Checkup command allows you to keep your project in top shape.
Command includes:
- Engine check - Ensures that you are using the right NodeJS version.
- Integrity - (yarn only) Ensures that dependencies are installed properly.
- Dependency duplicates check - (yarn only) Ensures no unnecessary dependency duplicates. Especially useful for monorepos.
- Linter - Strict ESLint rules.
- TypeScript check - Detects type errors and unused code.
- Formatting - Runs Prettier.
Command is aware of yarn workspaces and is able to run checks on whole monorepo or just in one package. 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.
💡 We recommend to run this command before pull requests and deployments.
> Ensure configs
$ opinionated ensure-configs
Command will add the following configs if necessary:
- EditorConfig - Makes sure that every developer use the same indentation, charset, EOF, etc.
- Prettier - Makes sure that every supported editor use the same auto-formatting rules.
💡 This command is usually not necessary as every other command runs it by default.
Integration into project
To integrate the tool into your project, we recommend the following packages.json
:
{
...
"scripts": {
"checkup": "opinionated checkup",
"prepare": "husky install"
},
"devDependencies": {
"@deftomat/opinionated": "^1.0.0",
"husky": "^8.0.0"
}
...
}
This configuration allows you to automatically run pre-commit check before each commit (via Husky git hook) and provides yarn checkup
to easily run checkup command.
Custom ESLint rules
If you need to alter the predefined ESLint rules, just follow the ESLint configuration guide.
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.
Ignoring files and directories
As tool is using ESLint and Prettier, you can follow their guidelines to ignore any file or directory.
However, when tool detects, that there are no .ignore file for these tools, then it tries to use .opinionatedignore
file which will be applied to both ESLint and Prettier. If there is no .opinionatedignore
, then .gitignore
will be used.
Resolution order for ESLint:
.eslintignore
eslintIgnore
property inpackage.json
.opinionatedignore
.gitignore
Resolution order for Prettier:
.prettierignore
.opinionatedignore
.gitignore