1.0.6 • Published 1 year ago

prettier-please v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

prettier-please License: MIT

A CLI tool to setup Prettier and pre-commit hooks. Heavily inspired by Create React App.

Feedback is welcome. 🙏

Setup

Execute in the root directory of your project:

npx prettier-please

This will install the dependencies Prettier, Husky and lint-staged inside your project. It will further setup a pre-commit hook to automatically format your files before committing them. No more discussions on code style during code reviews. 😉

How to remove

First uninstall the dependencies:

npm uninstall prettier husky lint-staged

Then remove the properties husky and lint-staged from your project's package.json:

{
- "husky": {
-   "hooks": {
-     "pre-commit": "lint-staged"
-   }
- },
- "lint-staged": {
-   "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
-     "prettier --write",
-     "git add"
-   ]
- }
}

Hint: You can always return to beautifully formatted code by executing npx prettier-please again. 🤫

FAQ

My code is not formatted automatically. Why is that?

prettier-please makes some assumptions about where your source code is located and which files to format (namely "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}"). To fix this, please adapt the path defined in the lint-staged property inside your project's package.json to your needs.

Example:

{
  "lint-staged": {
-   "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
+   "code/**/*.{php,html,yml}": [
      "prettier --write",
      "git add"
    ]
  }
}

Why would I use pre-commit hooks when I have Prettier enabled in my editor?

Good question! While using Prettier inside your editor might be sufficient when developing on your own, it probably won't be when working in a team. Other developers on your team might not have configured their editors to format code automatically. Using Prettier in combination with pre-commit hooks ensures that your code is always formatted correctly.

Is this for JavaScript projects only?

Nope! Prettier can be configured to work with many languages other than JavaScript (e.g. PHP). For more info, visit the official Prettier documentation.

You'll need a package.json file inside your project. This can be generated by executing npm init.

1.0.6

1 year ago

1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago