prettier-cli icon indicating copy to clipboard operation
prettier-cli copied to clipboard

Keep unknown keys in `overrides[].options`

Open tryone144 opened this issue 6 months ago • 4 comments

Related to an issue raised in https://github.com/prettier/prettier-cli/issues/70

Current behaviour only keeps the known configuration directives in the options object of an override. This implicitly drops any plugin configuration, while upstream prettier (legacy CLI) keeps them.

This PR copies the whole options object and only normalizes the know directives — similar to how the top-level configuration object is constructed. This now allows overriding plugin configuration for specific files.

Let me know if this isn't the way we want to go or if plugin options should be handled more strictly.

tryone144 avatar Jun 23 '25 17:06 tryone144

Thanks, I had previously reported this in https://github.com/prettier/prettier-cli/issues/9, which was fixed, but seems to have been subsequently broken again?

IanVS avatar Jul 10 '25 14:07 IanVS

This looks good but can we find out why 3517afc didn't fix it already? Afaict it was intended to

Maybe we need @fabiospampinato to have a quick look before we merge this

43081j avatar Jul 14 '25 10:07 43081j

I have a hard time believing that https://github.com/prettier/prettier-cli/commit/3517afc829ebdb602dfd5a998ad690b2bed13ef5 actually fixed this before. Its changes are limited to the CLI parsing and don't touch the config file validation directly.

I can reproduce the issue (plugin options are not respected in overrides of config file) with said commit as well as tagged release v0.5.0 that was used in the v4.0.0-alpha.9 release of prettier.

Example config

File .prettierrc.yml:

# All files
useTabs: true
tabWidth: 4
singleQuote: true
printWidth: 120

# JS/TS specific
trailingComma: es5
htmlWhitespaceSensitivity: ignore
arrowParens: avoid
quoteProps: preserve

plugins:
    - '@ianvs/prettier-plugin-sort-imports'

importOrder:
    - '^@core/(.*)$'
    - '^@server/(.*)$'
    - ''
    - '^@ui/(.*)$'

overrides:
    - files: 'frontend/**/*'
      options:
          useTabs: false
          tabWidth: 2

    - files: 'frontend/backend/**/*'
      options:
          importOrder:
              - '^@ui/(.*)$'
              - ''
              - '^@core/(.*)$'
              - ''
              - '^@server/(.*)$'

tryone144 avatar Jul 14 '25 11:07 tryone144

makes sense 👍

that's all i was wondering, didn't have time to investigate it myself

i do wonder if the normalizeFormatOptions function should just start with {...options} itself. but lets wait and see what Fabio thinks of this

43081j avatar Jul 14 '25 12:07 43081j