Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate .prettierrc file

I found this file .prettierrc inside a project. I would like to know how to generate it from visual studio code. Or I just create a new file named .prettierrc?

I tried to find something on internet but i am still confused

like image 605
Chris Garcia Avatar asked Aug 30 '20 15:08

Chris Garcia


People also ask

How do I open a prettierrc file?

You can open a PRETTIERRC file in any text or source code editor. Prettier is a code formatting tool that developers can use to automatically format their code using preset guidelines. Some of these guidelines can be adjusted using Prettier configuration files.

How do I configure the prettier configuration file?

Configuration File. Prettier uses cosmiconfig for configuration file support. This means you can configure Prettier via (in order of precedence): A "prettier" key in your package.json file. A .prettierrc file written in JSON or YAML. A .prettierrc.json, .prettierrc.yml, .prettierrc.yaml, or .prettierrc.json5 file.

How to use prettier in Git?

You can use Prettier from command line, or from your code editor whenever you paste or save a file. I prefer to use two solutions described in this blog post: format the changed files on Git commit before committing them Let me show you how to do both. When setting up Prettier it is important to configure it per-project.

What file format does prettier use?

Configuration File. Prettier uses cosmiconfig for configuration file support. This means you can configure prettier via: A .prettierrc file, written in YAML or JSON, with optional extensions: .yaml/.yml/.json. A .prettierrc.toml file, written in TOML (the .toml extension is required).


1 Answers

Here is the documentation.

If you go to the package.json file in your project, you probably will see that prettier is listed on the devDependencies.

As you can see in the documentation, you'll have to install it within your node project with:

npm install --save-dev --save-exact prettier

and then create the file manually with:

echo {}> .prettierrc.json

After that, you just need to configure it with your preferences. Check this examples.

Keep in mind that one common usage of prettier, is using it integrated it with linters. Check this documentation as well.

like image 151
rleiva93 Avatar answered Oct 18 '22 01:10

rleiva93