Page MenuHomeSealhub

Prettier - formatter kodu
Updated 595 Days AgoPublic

Prettier is an automatic code formatter. Unlike other linters, it doesn't just complain when the code doesn't adhere to formatting standards, but it can also automatically fix it.

Using Prettier eliminates arguments about code formatting and allows you to focus on what the code does during reviews, rather than how it looks :)

Example

You can see Prettier in action here

Installation

To install Prettier, run:

# npm install -g prettier

Make sure you're using prettier 1.15.1 or newer:

$ prettier -v                                                                                                                   
1.15.1

Then configure your IDE to use Prettier for supported languages:

https://github.com/prettier/prettier#editor-integration

Use this prettier config: https://hub.sealcode.org/diffusion/PLAY/browse/master/.prettierrc

You can put a copy of the above linked file in the root of your project - then your IDE should automatically pick that up and pass to Prettier.

Emacs

If you're using straight, this config should work fine:

.emacs.d/init.el
(setq exec-path (append exec-path '("/home/kuba/.nvm/versions/node/v6.11.2/bin"))) ;; find your path to prettier with `which prettier` and remove `prettier` from the path and use that path as the string in this setting


(use-package prettier
  :straight t
  :hook (typescript-ts-mode
         js-ts-mode
         web-mode
         html-mode
         css-mode
         scss-mode
         css-ts-mode
         json-mode
         yaml-mode
         json-ts-mode
         tsx-ts-mode
         yaml-ts-mode
         typescript-ts-base-mode))

VS Codium / VS Code

After installing Prettier on your system (see the commands at the beginning of this article), open VS Codium, launch the "Command Palette" using the key combination ⌃+shft+P.

VSCodium_176.png (707×562 px, 51 KB)

Type "Install extensions" and press ⏎.

VSCodium_177.png (707×562 px, 52 KB)

In the extensions search bar, type "prettier" and select the first option:

VSCodium_178.png (707×562 px, 80 KB)

After successful installation, click "reload":

Extension: Prettier - Code formatter - VSCodium_179.png (707×562 px, 117 KB)

Prettier is now installed! Now it's time to configure it. Open the "Settings" view using the Command Palette:

VSCodium_181.png (707×562 px, 64 KB)

Type "prettier" in the search bar:

Settings - VSCodium_182.png (707×562 px, 62 KB)

and then set the following options to the specified values:

image.png (288×91 px, 5 KB)

image.png (419×158 px, 16 KB)

image.png (200×59 px, 4 KB)

In the configuration, also set "format on save" to true:

image.png (705×561 px, 61 KB)

If saving still doesn't work, try setting Prettier as the default formatter: [Ctrl+,] -> "Editor: Default Formatter" -> "esbenp.prettier-vscode".

Project Tags
  • Unknown Object (Project)
Referenced Files
F45802: image.png
Nov 27 2018, 13:09
F44556: image.png
Nov 11 2018, 11:23
F44552: image.png
Nov 11 2018, 11:23
F44550: Settings - VSCodium_182.png
Nov 11 2018, 11:23
F44546: Extension: Prettier - Code formatter - VSCodium_179.png
Nov 11 2018, 11:23
F44548: VSCodium_181.png
Nov 11 2018, 11:23
F44542: VSCodium_177.png
Nov 11 2018, 11:23
F44544: VSCodium_178.png
Nov 11 2018, 11:23
Subscribers
None
Last Author
kuba-orlik
Last Edited
Mar 23 2025, 12:45

Event Timeline

kuba-orlik edited the content of this document. (Show Details)
kuba-orlik edited the content of this document. (Show Details)
kuba-orlik edited the content of this document. (Show Details)
kuba-orlik edited the content of this document. (Show Details)
kuba-orlik added a project: Unknown Object (Project).Jul 20 2018, 13:55
kuba-orlik edited the content of this document. (Show Details)
kuba-orlik shifted this object from the Restricted Space space to the S5 Publiczna space.Sep 20 2019, 18:13