Loading repository data…
Loading repository data…
jonlabelle / repository
JsPrettier is a Sublime Text Plug-in for Prettier, the opinionated code formatter.
[JsPrettier] is a Sublime Text Plugin for [Prettier], the opinionated code formatter.
[Watch a Quick Demo]
[JsPrettier] is compatible with both Sublime Text 2 and 3, and all supported Operating Systems.
If you've already installed [Prettier], you're all set... otherwise:
# npm (local)
npm install --save-dev prettier
# npm (globally)
npm install --global prettier
# or
# pnpm (local)
pnpm add -D prettier
# pnpm (globally)
pnpm add -g prettier
# or
# yarn (local)
yarn add prettier --dev
# yarn (globally)
yarn global add prettier
The recommended way to install JsPrettier is via [Package Control].
From the main application menu:
SublimeJsPrettier-master to JsPrettier.Default Sublime Text Packages Paths:
~/Library/Application Support/Sublime Text [2|3]/Packages~/.Sublime Text [2|3]/Packages%APPDATA%/Sublime Text [2|3]/Packages[!NOTE]
Replace the[2|3]part with the appropriate Sublime Text version for your installation.
If you're a Git user, you can install [JsPrettier] and keep it up-to-date by cloning the repository directly into your [Sublime Text Packages directory].
TIP: You can locate your Sublime Text Packages directory by using the application menu
Preferences->Browse Packages....
git clone https://github.com/jonlabelle/SublimeJsPrettier.git "JsPrettier"
JsPrettier allows you to format your code using Prettier directly within Sublime Text.
There are three available options to format code:
JsPrettier formats selected code first; if no selection is made, it formats the
entire file. When auto_format_on_save is enabled, the entire file will be
formatted on save.
To add a [custom key binding], open the Sublime Text key bindings file by
navigating to Preferences -> Key Bindings and add the following configuration:
{ "keys": ["ctrl+alt+f"], "command": "js_prettier" }
Configure plugin settings and Prettier options via the application menu:
debug (default: false)
When enabled (true), debug info will print to the console - useful for
troubleshooting and inspecting generated commands passed to Prettier.
Enabling debug mode also sets Prettier's [--log-level] option to debug
(when not overridden by additional_cli_args), for printing additional
debug information to the console.
prettier_cli_path (default: empty)
If Sublime Text has problems automatically resolving a path to [Prettier],
you can set a custom path here. When the setting is empty, the plugin will
attempt to find Prettier by:
Examples:
{
// macOS and Linux examples:
"prettier_cli_path": "/usr/local/bin/prettier",
"prettier_cli_path": "/some/absolute/path/to/node_modules/.bin/prettier",
"prettier_cli_path": "./node_modules/.bin/prettier",
"prettier_cli_path": "~/bin/prettier",
"prettier_cli_path": "$HOME/bin/prettier",
"prettier_cli_path": "${project_path}/bin/prettier",
"prettier_cli_path": "$ENV/bin/prettier",
"prettier_cli_path": "$NVM_BIN/prettier",
// Windows examples:
"prettier_cli_path": "C:/path/to/prettier.cmd",
"prettier_cli_path": "%USERPROFILE%\\bin\\prettier.cmd"
}
node_path (default: empty)
If Sublime Text has problems resolving the absolute path to node, you can
set a custom path here.
Examples:
{
// macOS/Linux:
"node_path": "/usr/local/bin/node",
"node_path": "/some/absolute/path/to/node",
"node_path": "./node",
"node_path": "~/bin/node",
"node_path": "$HOME/bin/node",
"node_path": "${project_path}/bin/node",
"node_path": "$ENV/bin/node",
"node_path": "$NVM_BIN/node",
// Windows:
"node_path": "C:/path/to/node.exe",
"node_path": "%USERPROFILE%\\bin\\node.exe"
}
auto_format_on_save (default: false)
Automatically format the file on save.
auto_format_on_save_excludes (default: [])
File exclusion patterns to ignore when auto_format_on_save is enabled.
useTabs (internally set by the [translate_tabs_to_spaces] setting)
Indent lines with tabs.
printWidth (default: 80)
Specifies that the formatted code should fit within this line limit.
tabWidth (default: 2)
Specify the number of spaces per indentation-level.
IMPORTANT: By default, "tabWidth" is aut
Example:
{
"auto_format_on_save_excludes": [
"*/node_modules/*",
"*/file.js",
"*.json"
]
}
auto_format_on_save_requires_prettier_config (default: false)
Enable auto format on save only when a Prettier config file is (or isn't)
found.
The Prettier config file is resolved by first checking if a --config-path <path> or --config <path>
is specified in the additional_cli_args setting, then by searching the
location of the file being formatted, and finally navigating up the file tree
until a config file is (or isn't) found. When --experimental-cli is present
in additional_cli_args, the plugin uses --config-path; otherwise --config is used.
allow_inline_formatting (default: false)
Enables the ability to format selections of in-lined code. For example, to
format a selection of JavaScript code within a PHP or HTML file. When
true, the JsPrettier command is available for use across all Sublime
Text syntaxes.
custom_file_extensions (default: [])
There's built-in support already for js, jsx, cjs, mjs, json,
jsonc, json5, html, hbs, graphql/gql, ts, tsx, cts, mts, css,
scss, less, md, mdx, yml, yaml, vue and component.html
(angular html) files.
Put additional file extensions here, and be sure not to include the leading dot in the file extension.
max_file_size_limit (default: -1)
The max allowed file size to format in bytes. For performance reasons,
files with a greater file size than the specified max_file_size_limit will
not format. Setting the max_file_size_limit value to -1 disables the
file size checking (default).
disable_tab_width_auto_detection (default: false)
Whether or not to disable the plugin from automatically setting Prettier's
--tab-width
option, and adhere to the Prettier configured setting.
disable_prettier_cursor_offset (default: false)
There's an apparent (and nasty) defect in Prettier that seems to occur
during Prettier's cursor offset
calculation, and when attempting to format large or minimized files (but not limited to just these cases).
The issue effectively results in the CPU spiking to a constant 100%...
indefinitely, or until the node executable/process running Prettier is
forcefully terminated.
To avoid this problematic behavior, or until the defect is resolved, you can
disable the plugin (JsPrettier) from ever passing the cursor offset
position to Prettier by setting the disable_prettier_cursor_offset value
to true.
additional_cli_args (default: {})
A key-value pair of arguments to append to the prettier command.
Examples:
{
"additional_cli_args": {
"--config-path": "~/.prettierrc", // use with --experimental-cli
// or
"--config": "~/.prettierrc", // classic Prettier (no --experimental-cli)
// or
"--config-path": "$HOME/.prettierrc",
// or
"--config-path": "${project_path}/.prettierrc",
// or
"--config-path": "/some/absolute/path/to/.prettierrc",
"--config-precedence": "file-override",
"--ignore-path": "${file_path}/.prettierignore",
"--with-node-modules": "",
"--plugin-search-dir": "$folder"
}
}