Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A CLI tool to setup Prettier and pre-commit hooks.

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages