Prettier-er Formatter for Visual Studio CodePrettier-er is an open-minded code formatter based on Prettier. It provides additional configuration options, allowing you to tailor the formatting rules to better suit your project's needs.
JavaScript
· TypeScript
· Flow
· JSX
· JSON
InstallationInstall through VS Code extensions. Search for Visual Studio Code Market Place: Prettier-er - Code formatter Can also be installed in VS Code: Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Prettier-ERPrettier-er is built off of Prettier, and as such, shares most of its archecture with Prettier. The following documentation is largely centered around Prettier-er, focusing on the changes in this version of the formatter. For full documentation of the original formatter, visit Prettier Docs. Default FormatterTo ensure that this extension is used over other extensions you may have installed, be sure to set it as the default formatter in your VS Code settings. This setting can be set for all languages or by a specific language.
If you want to disable Prettier-er on a particular language you can either create a The following will use Prettier-er for all languages except Javascript.
The following will use Prettier-er for only Javascript.
Additionally, you can disable format on save for specific languages if you don't want them to be automatically formatted.
Visual Studio Code SettingsYou can use VS Code settings to configure prettier. Settings will be read from (listed by priority):
UsageUsing Command Palette (CMD/CTRL + Shift + P)
Formatting using Menu Bar
Changes from Prettier-erThe changes Prettier-er makes to Prettier primarially come in two categories:
Formatting AdditionsPrettier-er primarily adds optional code style formatting choices that change how the formatter works. Each of these can be enabled in VS Code's workspace settings, and are enumerated in Prettier-er Settings. Allman StyleAllman style places a newline character before each '{' character. For example: Disabled:
Enabled:
Force Object BreakThis setting forces object literals to exist on one or multiple lines, depending on the setting. The default setting preserves the existing Prettier functionality. Assume the following code for the next two settings:
Preserve Functionality determines the status of individual objects, meaning that each object literal must be set to single or multi line. The following two apply to all object literals forceSingleLine:
forceMultiLine:
NOTE: A current bug does not apply allman style to object literal breaks. This will be addressed in the future. Matrix ArrayMatrix array allows for arrays to be initialized on multiple lines, as in a matrix. With the setting enabled: Formatting any array produces:
To make the array into a matrix, place a newline after the final entry in any row, before the ','.
When formatting is run, the array will be ordered like a matrix:
Get Set One LineUnstable: Get Set One Line currently does not function reliably. Further bug fixes will be needed to restore it. Get Set One Line automatically compresses getter and setter functions to a single line if:
For example,
Will be formatted to,
Else Statement New LineElse Statement New Line places the Disabled:
Enabled:
Multi Empty LineMulti Empty Line allows for multiple lines of whitespace at the start and end of blocks. This setting allows for code such as:
To remain spaced, instead of collapsing to:
when the setting is disabled. Retain Blank LinesSimilar to Multi Empty Line, Retain blank lines allows for whitespace anywhere in a document, instead of being collapsed into a single line. This allows for code such as:
To remain spaced, instead of collapsing to:
when the setting is disabled. Selectors Same LineA css setting that allows multiple selectors to be on the same line. Disabled:
Enabled:
Readability AnalysisPrettier-er includes a new tool developed to congregate metrics that indicate readability of code. Our Readability Analysis tool is entirely optional, and is intended to be used by new programmers who want guidance on how to make their code more readable, but can be useful to anyone. How to useReadability analysis can be performed on any document in VS Code by running a command in the same way one formats a document using Prettier-er. In the searchbar at the top of your workspace, type '>' to reveal commands. From here, search for The tool uses 6 metrics to assess the readability of a document. These are:
Each of these metrics are found from your open document and compared against thresholds set in your workspace settings. These thresholds can be changed at any time. If any metric breaks a threshold (Your average line length is too high, or your ratio of comment to code is too low), a separate message will be shown, suggesting improvements. Below is a sample of the readability analysis This is the result of using In addition to metrics, any identifiers that below a certain length are pointed out, with their related line number. This recommendation exists to encourage more informative variable names, and the threshold for length can be changed, just like the other metrics. SettingsPrettier-er SettingsAll Prettier and Prettier-er options can be configured directly in this extension.
prettier.forceObjectBreak prettier.matrixArray prettier.allmanStyle prettier.getSetOneLine prettier.elseStatementNewLine prettier.multiEmptyLine prettier.retainBlankLines prettier.selectorsSameLine prettier.lineLengthRead prettier.nestingCountRead prettier.memAccessRead prettier.commentToCodeRatioRead prettier.whitespaceRatioRead prettier.IDCountRead prettier.IDMinLengthRead
Error MessagesFailed to load module. If you have prettier or plugins referenced in package.json, ensure you have run When a Your project is configured to use an outdated version of prettier that cannot be used by this extension. Upgrade to the latest version of prettier. You must upgrade to a newer version of prettier. This workspace is not trusted. Using the bundled version of prettier. You must trust this workspace to use plugins and local/global modules. See: Workspace Trust |