diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 5397e1ad..2a67ba57 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d394c8..f460f70d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/JsPrettier.py b/JsPrettier.py index 8c9d72fa..60040c86 100644 --- a/JsPrettier.py +++ b/JsPrettier.py @@ -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( @@ -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 ` option is set in 'additional_cli_args', - # no action is necessary. otherwise, try to sniff the config - # file path: + # if a `--config-path ` or `--config ` 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 @@ -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 ' 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: @@ -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( diff --git a/JsPrettier.sublime-settings b/JsPrettier.sublime-settings index d227dff6..8d8fb698 100644 --- a/JsPrettier.sublime-settings +++ b/JsPrettier.sublime-settings @@ -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 ` - // 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 ` or + // `--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. 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, @@ -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": "", diff --git a/README.md b/README.md index 17f947ea..b6654ff8 100644 --- a/README.md +++ b/README.md @@ -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 ` + The Prettier config file is resolved by first checking if a `--config-path ` or `--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. + 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 @@ -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", @@ -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 ` -key-value item to `additional_cli_args`. Here's an example: +To specify a custom Prettier config path, add `--config-path ` (when using +`--experimental-cli`) or `--config ` (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" } diff --git a/messages.json b/messages.json index 51f72865..b8aa3d60 100644 --- a/messages.json +++ b/messages.json @@ -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" } diff --git a/messages/1.91.0.txt b/messages/1.91.0.txt new file mode 100644 index 00000000..ad3348fc --- /dev/null +++ b/messages/1.91.0.txt @@ -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.