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
Configuring pre-commit for jsx, Typescript, tsx #2745
Comments
I think it's because by default the hooks only target javascript and not jsx: prettier/.pre-commit-hooks.yaml Line 5 in 9c4ec68
from identify, jsx is identified as "jsx" and not "javascript": You could overwrite that with |
pre-commit maintainer here! When I set up the integration here I didn't know enough about prettier it seems :) -- One option would be to change the - types: [javascript]
+ files: \.(js|jsx|ts|tsx)$ this unfortunately would lose linting of extensionless files as well... maybe this is ok for prettier? imo this is probably the best solution for the short term. Another idea you could implement just with your own configuration would be to duplicately use the - repo: https://github.com/prettier/prettier
sha: 'a29b407' # Use the sha or tag you want to point at
hooks:
- id: prettier
name: prettier (js)
- id: prettier
name: prettier (jsx)
# override the default `types: [javascript]`
types: [jsx]
- id: prettier
name: prettier (typescript)
# identify doesn't yet know about ts / tsx files, a pull request would be great! https://github.com/chriskuehl/identify
# reset the `types` detection to the default
types: [file]
files: \.(ts|tsx)$ As for the configuration file, I'm not sure of |
Those are all the file types prettier handles by default: Lines 32 to 42 in 133303f
@asottile when you did the integration, prettier only handled js and jsx, we expanded a bit the scope of prettier since then ;) |
Awesome, should we approach this by listing extensions supported by |
@asottile whatever works for you, I'll be happy to merge a PR to update the config :) |
Sweet, here's my proposal in PR form: #2759 |
@reywright the latest configuration (just merged) should support ts / tsx as well -- thanks for the issue! To get the latest version (before a tagged release is made in @chriskuehl thanks again for pinging :D |
There's not a lot of documentation on how to use the pre-commit method (maybe that's by design?) but this is what I've done.
.pre-commit-config.yaml
.App.jsx
Then I see this:
This is working on regular js files if I attempt to commit them, but not jsx or tsx (I didn't try regular ts).
As to why I'm using pre-commit, it's in the Readme as being acceptable to use, and I'd also like to keep the ability to stage hunks without staging the entire file.
I also have a followup question: does the pre-commit stuff use the .prettierrc config file, or do you need to pass in your own styles? If so, how do you do this as well?
The text was updated successfully, but these errors were encountered: