Configuring pre-commit for jsx, Typescript, tsx
See original GitHub issueThere’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.
pip install pre-commit
touch .pre-commit-config.yaml
.pre-commit-config.yaml
- repo: https://github.com/prettier/prettier
sha: 'a29b407' # Use the sha or tag you want to point at
hooks:
- id: prettier
pre-commit install
pre-commit autoupdate
.App.jsx
export default class extends Component {
handleChange = (e) => {
this.setState({
input: e.target.value,
});
console.log('aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah');
console.log('aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah');
console.log('aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah');
console.log('aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah', 'aye', 'foo', 'blah', 'blah');
[
'lorem',
'ipsum',
'dolor',
sit('amet'),
consectetur['adipiscing'] + 'elit',
].reduce((first, second) => first + second, '');
}
// ...
// ....
git add --all
git commit
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?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Configuring Prettier and TypeScript Compiler as a Pre-commit ...
1. Install prettier, husky and lint-staged · 2. Configure prettier · 3. Create a lint-staged config file: .lintstagedrc: · 4. Create a husky...
Read more >Pre-Commit Hooks for Pretter and ESLint in TypeScript Projects
Learn how to configure your TypeScript project to automatically prettify and lint your code before committing to git using husky.
Read more >How to Add ESLint, Prettier, and Husky (Git Hooks) to Your ...
A complete guide on adding Eslint with Prettier to a TypeScript React project and running pre-commit command on each Git commit command.
Read more >Build a robust React app with Husky pre-commit hooks and ...
Building robust React projects may seem complex at first, but this guide will explain how you can do so with Husky hooks and...
Read more >Husky + Lint-Staged on a React TypeScript Project
Setting up to commit only if all Unit Tests passed. To trigger some action before committing, we will use the Git Hook called...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
prettier
) you can usepre-commit autoupdate --bleeding-edge
(this will get the latest revision ofmaster
instead of the latest tag). Or use 4d68faf or newer.@chriskuehl thanks again for pinging 😄 @vjeux if there’s additional issues about
pre-commit
integration now or in the future, feel free to ping me 😃Sweet, here’s my proposal in PR form: https://github.com/prettier/prettier/pull/2759