flake8-quotes icon indicating copy to clipboard operation
flake8-quotes copied to clipboard

No error after outer quotes are changed per Q003 if inner quotes are still escaped

Open rpdelaney opened this issue 5 years ago • 3 comments

Possibly related #69 , #77

  1. 'str\'i\'ng' Q003
  2. "str\'i\'ng" No errors

The first line gives Q003 while the second line emits no errors. I took the ultimate aim of Q003 to be to eliminate escaped quotes wherever possible: if I am correct, then I suggest we should emit an additional error to actually do the un-escaping.

I don't have a considered opinion about what that should look like, but if the pump needs priming it could be something like Q004 "Remove unnecessarily escaped quotes."

rpdelaney avatar May 11 '20 21:05 rpdelaney

Seems like a reasonable request :+1:

I think that Q004 "Remove unnecessarily escaped quotes" sounds good to me =) (no period needed)

twolfson avatar May 11 '20 21:05 twolfson

There's a plugin flake8-strings that says on the tin that is does this, but I haven't tried it. MIT license. Maybe we could crib from there.

rpdelaney avatar May 16 '20 23:05 rpdelaney

This seems reasonable to me, but I think a little nuiance is needed to handle cases of literal backslashes:

  • 'str\'i\'ng - Q003
  • "str\'i\'ng" - Q004
  • "str\\'i\\'ng" - Acceptable, since \\' is intended to produce the literal \' rather than to escape '
  • r"str\'i\'ng" - Acceptable, since \' is interpreted literally by raw strings

There are probably more cases to consider along these lines too!

JoeHitchen avatar Dec 11 '22 19:12 JoeHitchen