prettier-config-nahid
My sharable and pluggable Prettier configuration.
Contents
Features
- Formats code using Prettier.
Requirements
Installation
- If your project doesn't have a
package.json
file already, create one using thenpm init
command. - Run the command:
npx install-peerdeps --dev prettier-config-nahid
- In your
package.json
file, reference the config using theprettier
property, in the following way;
"prettier": "prettier-config-nahid"
Learn more about using shareable Prettier config here.
Usage
- You can try running the following command
prettier --check .
to run Prettier. Look at Prettier's command-line interface guide here. - I prefer adding two scripts to the
package.json
file:
"scripts": {
"format": "prettier --check \"**/*.{html,json,md}\"",
"format:fix": "prettier --write \"**/*.{html,json,md}\""
}
That way, I can run npm run format
and npm run format:fix
to check formatting and check/format all the HTML, JSON, and MD files in the codebase.
The documentation for Prettier as a whole can be found here.
FAQ
wp-prettier
?
Why I started my career in software development with WordPress, and I'm really fond of the coding standards WordPress has been enforcing recently. I've been using them for quite a very long time now and I'm very used to them, which is why I like to carry them onto my other (non-WordPress) projects as well. You should also see that this config includes @wordpress/prettier-config
carrying over coding standards from the WordPress ecosystem.
My Prettier config uses wp-prettier
as prettier
. wp-prettier
is a fork of prettier
created by my folks at WordPress. It adds a new command line option --paren-spacing
which inserts extra spaces inside parentheses, the way how projects in the WordPress ecosystem, and I like to format their code.