13

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.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
sreejith
  • 213
  • 2
  • 8

2 Answers2

1

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

AsankaJ
  • 82
  • 7
  • 5
    Your answer is about the VSCode feature "Only format modified text", but the questioner asks for solution using Prettier. – BuZZ-dEE Jun 29 '22 at 15:44
-3

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.

RamiroP
  • 360
  • 1
  • 8
  • 1
    Yes, it's the big diff I'm trying to avoid. Also, trying to introduce the formatting without a big initial commit. You have a point there, probably will create a bigger Frankenstein than current. But technically, do you know if any such solution exists or even possible with eslint – sreejith Oct 17 '20 at 18:46