Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file extension-specific configuration #17

Closed
midgleyc opened this issue May 3, 2022 · 7 comments · Fixed by #20
Closed

Support file extension-specific configuration #17

midgleyc opened this issue May 3, 2022 · 7 comments · Fixed by #20
Labels
enhancement New feature or request

Comments

@midgleyc
Copy link

midgleyc commented May 3, 2022

Thanks for making this -- it's a lot faster than prettier straight.

Unfortunately I can't port my config over. Prettier supports automatically reading config from a .editorconfig file, and I'm using that to use single quotes in .ts files and double quotes elsewhere (e.g. SCSS)

[*]
quote_type = double

[*.ts]
quote_type = single

Could you make it possible to specify prettier config for extensions individually? For example, something like:

{
  "prettier": {
    "singleQuote": false,
    "ts.singleQuote": true
  }
}

would translate the above (although there might be a better design).

@dsherret dsherret added the enhancement New feature or request label May 3, 2022
@midgleyc
Copy link
Author

Turns out prettier already supports this as

"singleQuote": false,
"overrides": {         
  "files": ["**/*.ts"],                                                                                  
  "options": {                                                                                           
    "singleQuote": true                                                                                  
  }                                                                                                      
}

This fails while parsing the object:

Error deserializing. Expected a boolean, string, or number in object property 'prettier -> overrides'

@dsherret
Copy link
Member

Oh nice! I just need to implement dprint/dprint#530 in that case

@dsherret
Copy link
Member

@midgleyc the "overrides" is supported now. Thanks for investigating that! You will need to upgrade to dprint 0.28 and dprint-plugin-prettier 0.8 though

@midgleyc
Copy link
Author

Hi @dsherret . Thanks for the prompt update, I see that dprint is now reading the configuration file.

Unfortunately it is not working for me. I have put together a repository at https://github.com/midgleyc/dprint-prettier-test to show the issue: with the same config across prettier and dprint, prettier picks up the overrides, but it seems dprint does not.

@dsherret dsherret reopened this May 12, 2022
@dsherret
Copy link
Member

@midgleyc very sorry, I looked into this a bit just now and this definitely doesn't work. I must have flipped some condition in my head when I was testing it manually.

Looking into it more, it would be trivial to add this for stuff like **/*.js, but for globs like ./some-dir/**/*.js the current approach wouldn't work because the plugin doesn't have knowledge about what directory the config was loaded from. I'm thinking instead this should be built into dprint's CLI in order to have config based on a certain directory.

That said, I think for the purposes of this plugin doing extension level config should work well and will solve your use case. So I'm going to implement your original suggestion tonight and it will more easily have automated tests:

{
  "prettier": {
    "singleQuote": false,
    "ts.singleQuote": true
  }
}

Once again, my bad, but fix will be incoming soon tonight.

@dsherret
Copy link
Member

Should be fixed now. Added a test and updated the readme: https://github.com/dprint/dprint-plugin-prettier#file-extension-specific-configuration

@midgleyc
Copy link
Author

Works great now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants