Prettier: Run for only the changed lines of the file

6k views Asked by At

I have a legacy codebase without eslint/prettier. I want to introduce formatting on pre-commit hooks. Lint staged will let you run prettier for only changed files. Is it possible to only run the prettier just for changed lines? Like IntelliJ's inbuild formatting allows for only VCS changed text formatting.

2

There are 2 answers

1
RamiroP On

Not a solution here, but can I ask why do you want to do this?

What you want to do would end up with messy files just like the ones you have now. You will not be adding real value to the codebase.

I assume the problem you are trying to avoid are those gigantic diffs on every merge request. I think is better to make a style / linting MR first and start from there.

1
AsankaJ On

Hope you have solved the issue by now. For others, A fix for this was introduced in the August 2020 (version 1.49) update. Check out this link for more info. link