Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ body:
attributes:
label: Prettier command
description: Generated `prettier` command line arguments. [Enable debug mode](https://github.com/jonlabelle/SublimeJsPrettier/blob/master/JsPrettier.sublime-settings#L18 "Go to debug option in JsPrettier.sublime-settings") and open the [console](https://docs.sublimetext.io/guide/getting-started/basic-concepts.html#the-console "Read more about the SublimeText console") to view.
placeholder: prettier --config ./prettierrc --stdin-filepath messy.js
placeholder: prettier --config-path ./prettierrc --stdin-filepath messy.js
render: console
validations:
required: false
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 1.91.0

**Release Date:** 2026-03-19

This release adds support for Prettier's `--config-path` CLI option, introduced in Prettier's
experimental CLI (`--experimental-cli`).

When `--experimental-cli` is present in `additional_cli_args`, the plugin automatically uses
`--config-path` to pass the resolved config file path to Prettier. Otherwise, the classic `--config`
flag is used. **No changes to your settings are required.**

Both `--config` and `--config-path` are accepted as keys in the `additional_cli_args` setting.

## 1.90.0

**Release Date:** 2025-10-10
Expand Down
28 changes: 18 additions & 10 deletions JsPrettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ def try_find_prettier_config(self, view):

#
# 1. Check if defined in 'additional_cli_args':
additional_cli_arg_config = get_cli_arg_value(self.additional_cli_args, '--config')
additional_cli_arg_config = get_cli_arg_value(self.additional_cli_args, '--config-path') \
or get_cli_arg_value(self.additional_cli_args, '--config')
if not is_str_none_or_empty(additional_cli_arg_config):
additional_cli_arg_config = str(additional_cli_arg_config)
additional_cli_arg_config = os.path.normpath(additional_cli_arg_config)
if not os.path.isabs(additional_cli_arg_config):
additional_cli_arg_config = in_source_file_path_or_project_root(
Expand Down Expand Up @@ -234,15 +236,17 @@ def run(self, edit, save_file=False, auto_format_prettier_config_path=None):
os.chdir(st_project_path)

#
# if a `--config <path>` option is set in 'additional_cli_args',
# no action is necessary. otherwise, try to sniff the config
# file path:
# if a `--config-path <path>` or `--config <path>` option is set in
# 'additional_cli_args', no action is necessary. otherwise, try to
# sniff the config file path:
parsed_additional_cli_args = parse_additional_cli_args(view.window(), self.additional_cli_args)
has_custom_config_defined = parsed_additional_cli_args.count('--config') > 0
has_custom_config_defined = parsed_additional_cli_args.count('--config-path') > 0 \
or parsed_additional_cli_args.count('--config') > 0
has_no_config_defined = parsed_additional_cli_args.count('--no-config') > 0

prettier_config_path = None
# only try to resolve prettier config if '--no-config' or '--config' are NOT in 'additional_cli_args'
# only try to resolve prettier config if '--no-config', '--config-path',
# or '--config' are NOT in 'additional_cli_args'
if not has_no_config_defined and not has_custom_config_defined:
if save_file and auto_format_prettier_config_path and os.path.exists(auto_format_prettier_config_path):
prettier_config_path = auto_format_prettier_config_path
Expand Down Expand Up @@ -509,9 +513,11 @@ def parse_prettier_options(self, view, parsed_additional_cli_args, prettier_conf
prettier_config_exists = not is_str_none_or_empty(prettier_config_path)
if prettier_config_exists:
if not has_custom_config_defined:
# only add the '--config <path>' option if it's not
# already specified as an additional cli arg:
prettier_options.append('--config')
# use '--config-path' only when '--experimental-cli' is active (Prettier 3+),
# otherwise fall back to '--config':
use_experimental_cli = parsed_additional_cli_args.count('--experimental-cli') > 0
config_flag = '--config-path' if use_experimental_cli else '--config'
prettier_options.append(config_flag)
prettier_options.append(prettier_config_path)

else:
Expand Down Expand Up @@ -805,8 +811,10 @@ def try_find_prettier_config(self, view):

#
# 1. Check if defined in 'additional_cli_args':
additional_cli_arg_config = get_cli_arg_value(self.get_additional_cli_args(view), '--config')
additional_cli_arg_config = get_cli_arg_value(self.get_additional_cli_args(view), '--config-path') \
or get_cli_arg_value(self.get_additional_cli_args(view), '--config')
if not is_str_none_or_empty(additional_cli_arg_config):
additional_cli_arg_config = str(additional_cli_arg_config)
additional_cli_arg_config = os.path.normpath(additional_cli_arg_config)
if not os.path.isabs(additional_cli_arg_config):
additional_cli_arg_config = in_source_file_path_or_project_root(
Expand Down
18 changes: 10 additions & 8 deletions JsPrettier.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@
//
// Enable auto format on save ONLY when a Prettier config file is found.
//
// The Prettier config file is resolved by first checking if a `--config </path/to/prettier/config>`
// 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.
// 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`, `--config-path` is used; otherwise `--config` is used.
// ----------------------------------------------------------------------

"auto_format_on_save_requires_prettier_config": false,
Expand Down Expand Up @@ -243,10 +244,11 @@
// Examples:
//
// "additional_cli_args": {
// "--config": "path/to/my/custom/.prettierrc",
// "--config": "~/.prettierrc",
// "--config": "$HOME/.prettierrc",
// "--config": "${project_path}/.prettierrc",
// "--config-path": "path/to/my/custom/.prettierrc", // use with --experimental-cli
// "--config": "path/to/my/custom/.prettierrc", // classic Prettier (no --experimental-cli)
// "--config-path": "~/.prettierrc",
// "--config-path": "$HOME/.prettierrc",
// "--config-path": "${project_path}/.prettierrc",
// "--config-precedence": "prefer-file",
// "--ignore-path": "${file_path}/.prettierignore",
// "--with-node-modules": "",
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ Configure plugin settings and Prettier options via the application menu:
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/to/prettier/config>`
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.
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
Expand Down Expand Up @@ -292,13 +293,15 @@ Configure plugin settings and Prettier options via the application menu:
```jsonc
{
"additional_cli_args": {
"--config": "~/.prettierrc",
"--config-path": "~/.prettierrc", // use with --experimental-cli
// or
"--config": "$HOME/.prettierrc",
"--config": "~/.prettierrc", // classic Prettier (no --experimental-cli)
// or
"--config": "${project_path}/.prettierrc",
"--config-path": "$HOME/.prettierrc",
// or
"--config": "/some/absolute/path/to/.prettierrc",
"--config-path": "${project_path}/.prettierrc",
// or
"--config-path": "/some/absolute/path/to/.prettierrc",

"--config-precedence": "file-override",
"--ignore-path": "${file_path}/.prettierignore",
Expand Down Expand Up @@ -528,13 +531,14 @@ or selection(s) defined in Sublime Text.

#### Custom Prettier Config File Path

To specify a custom Prettier config path, simply add a `--config <path>`
key-value item to `additional_cli_args`. Here's an example:
To specify a custom Prettier config path, add `--config-path <path>` (when using
`--experimental-cli`) or `--config <path>` (classic Prettier) as a key-value item in
`additional_cli_args`. Both keys are accepted by the plugin. Here's an example:

```json
{
"additional_cli_args": {
"--config": "~/some/path/from/my/home/.prettierrc",
"--config-path": "~/some/path/from/my/home/.prettierrc",
"--config-precedence": "prefer-file",
"--ignore-path": "${project_path}/.prettierignore"
}
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
"1.64.0": "messages/1.64.0.txt",
"1.65.0": "messages/1.65.0.txt",
"1.70.0": "messages/1.70.0.txt",
"1.90.0": "messages/1.90.0.txt"
"1.90.0": "messages/1.90.0.txt",
"1.91.0": "messages/1.91.0.txt"
}
22 changes: 22 additions & 0 deletions messages/1.91.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
┌──────────────────────────────────────────────────────────────────────────────┐
│ _ ____ _ _ _ │
│ | |___| _ \ _ __ ___| |_| |_(_) ___ _ __ │
│ _ | / __| |_) | '__/ _ \ __| __| |/ _ \ '__| │
│ | |_| \__ \ __/| | | __/ |_| |_| | __/ | │
│ \___/|___/_| |_| \___|\__|\__|_|\___|_| │
│ │
└──────────────────────────────────────────────────────────────────────────────┘

## 1.91.0

Release date: 2026-03-19

This release adds support for Prettier's `--config-path` CLI option, introduced
in Prettier's experimental CLI (`--experimental-cli`).

When `--experimental-cli` is present in `additional_cli_args`, the plugin
automatically uses `--config-path` to pass the resolved config file path to
Prettier. Otherwise, the classic `--config` flag is used.

No changes to your settings are required. Both `--config` and `--config-path`
are accepted as keys in the `additional_cli_args` setting.