False-positive S1717 with raw f-strings

  • What language is this for?

  • Which rule?

  • Why do you believe it’s a false-positive/false-negative?
    Because neither rf"[{body}]" nor rf"\\[{body}\\]" give the expected result.

  • SonarLint v4.1.0 in VS Code

  • How can we reproduce the problem?

Imagine we want to build a regex that matches [foo], so we have to escape the brackets:

import re

string = "[foo]"
body = "foo"
pattern = rf"\[{body}\]"
print(re.match(pattern, string))

Hello Bers,

I haven’t managed to reproduce the issue. Can you please provide me with the exact code that raises the FP?

Additionally, I would like to mention that S1717 is a deprecated rule, and is not activated by default. We therefore don’t intend to continue making improvements to this rule.


Hi @jeremi.dodinh,
the above is the exact code:

I had been using

    "sonarlint.rules": {
        "python:S1717": {
            "level": "on"

S1717 is a deprecated rule, and is not activated by default

That’s good to know, thanks! (I should have seen this myself at Python static code analysis: "\" should only be used as an escape character outside of raw strings)

Feel free to close this if the rule is going away anyway.

I just ran into this today. The rule should be able to understand that fr'C:\Windows\{file}' and rf'C:\Windows\{file}' are perfectly valid.


Thanks for the new code example. I have successfully reproduced the false positive and created SONARPY-1906.

Have a great day,