Prettier is an opinionated code formatter with support for several programming languages including:
- JavaScript
- JSX
- Angular
- Vue
- Flow
- TypeScript
- CSS, Less, and SCSS
- HTML
- Ember/Handlebars
- JSON
- GraphQL
- Markdown, including GFM and MDX v1
- YAML
- go
- java
- kotlin
- php
- ruby
- rust
- sql
- and a host of other languages
To install Prettier run the following command from the command prompt:
Code: Select all
npm install --save-dev --save-exact prettier
Code: Select all
npx prettier --help
Code: Select all
Usage: prettier [options] [file/dir/glob ...]
By default, output is written to stdout.
Stdin is read if it is piped to Prettier and no files are given.
Output options:
-c, --check Check if the given files are formatted, print a human-friendly summary
message and paths to unformatted files (see also --list-different).
-l, --list-different Print the names of files that are different from Prettier's formatting (see also --check).
-w, --write Edit files in-place. (Beware!)
Format options:
...
For Prettier to work it needs a project folder containing a package.json file.
The simplest way to do create this project structure is to npm using the following command:
Code: Select all
npm init
Zeus can be configured to automatically run prettier each time the file is saved. To achieve this follow the
instructions found here: http://www.zeusedit.com/phpBB3/viewtopi ... =10&t=8145
Using Prettier inside Zeus
Start Zeus and use the Options, Document Types menu to edit the JScript Document Type.
In the Compiler panel enter the following details:
Code: Select all
Command Line: npx prettier --check "$fn"
Errors Regex: \[error\]
Warnings Regex: \[warn\]
(o) Display on errors and warnings
In the project folder initialized earlier, create a test.js file shown below:
foo(reallyLongArg(), omgSoManyParameters(), IShouldRefactorThis(), isThereSeriouslyAnotherOne());[/code]
Now with test.js as the active file use the Compiler, Compile menu to run the linter.
That should result in the output shown below: Using Prettier with the Write Option
If you change the command line described earlier to be the following:
Code: Select all
npx prettier --write "$fn"
Code: Select all
foo(
reallyLongArg(),
omgSoManyParameters(),
IShouldRefactorThis(),
isThereSeriouslyAnotherOne()
);
Cheers Jussi