pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.4k stars 710 forks source link

trailing-whitespace hook leads to different code(potentially creating unintended bugs) #1071

Closed fdobal closed 4 months ago

fdobal commented 4 months ago

When executing pre-commits hooks on the following code:

` from typing import Optional

RESNNMMTTT_BUCAAA_ABCD = '12345'
def f(dnda_classfifkqopwr: str, cdruhb: str) -> Optional[str]:
    if dnda_classfifkqopwr == "a":
        return RESNNMMTTT_BUCAAA_ABCD if cdruhb == "hh-lopcxsd-9" else f"{RESNNMMTTT_BUCAAA_ABCD}-{cdruhb}"

return None

`

the file is modified to this file:

` from typing import Optional

RESNNMMTTT_BUCAAA_ABCD = '12345'

def f(dnda_classfifkqopwr: str, cdruhb: str) -> Optional[str]:
    if dnda_classfifkqopwr == "a":
        return RESNNMMTTT_BUCAAA_ABCD if cdruhb == "hh-lopcxsd-9" else f"{RESNNMMTTT_BUCAAA_ABCD} -{cdruhb} "

    return None

`

Particularly take a look at the following part:

ABCD} -{

It adds an extra blank space.

Screenshot 2024-07-09 at 20 11 00 Screenshot 2024-07-09 at 20 16 05

It can be reproduced on Mac and Linux

Python version is 3.12.

The version used is v4.6.0.

asottile commented 4 months ago

I can't reproduce, must be some other tool?