---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF055 [*] Plain string pattern passed to `re` function
 --> RUF055_0.py:6:1
  |
5 | # this should be replaced with `s.replace("abc", "")`
6 | re.sub("abc", "", s)
  | ^^^^^^^^^^^^^^^^^^^^
  |
help: Replace with `s.replace("abc", "")`
  |
5 | # this should be replaced with `s.replace("abc", "")`
  - re.sub("abc", "", s)
6 + s.replace("abc", "")
7 |
  |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:22:4
   |
20 | # this one should be replaced with `s.startswith("abc")` because the Match is
21 | # used in an if context for its truth value
22 | if re.match("abc", s):
   |    ^^^^^^^^^^^^^^^^^^
23 |     pass
24 | if m := re.match("abc", s):  # this should *not* be replaced
   |
help: Replace with `s.startswith("abc")`
   |
21 | # used in an if context for its truth value
   - if re.match("abc", s):
22 + if s.startswith("abc"):
23 |     pass
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:29:4
   |
28 | # this should be replaced with `"abc" in s`
29 | if re.search("abc", s):
   |    ^^^^^^^^^^^^^^^^^^^
30 |     pass
31 | re.search("abc", s)  # this should not be replaced
   |
help: Replace with `"abc" in s`
   |
28 | # this should be replaced with `"abc" in s`
   - if re.search("abc", s):
29 + if "abc" in s:
30 |     pass
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:34:4
   |
33 | # this should be replaced with `"abc" == s`
34 | if re.fullmatch("abc", s):
   |    ^^^^^^^^^^^^^^^^^^^^^^
35 |     pass
36 | re.fullmatch("abc", s)  # this should not be replaced
   |
help: Replace with `s == "abc"`
   |
33 | # this should be replaced with `"abc" == s`
   - if re.fullmatch("abc", s):
34 + if s == "abc":
35 |     pass
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:39:1
   |
38 | # this should be replaced with `s.split("abc")`
39 | re.split("abc", s)
   | ^^^^^^^^^^^^^^^^^^
40 |
41 | # these currently should not be modified because the patterns contain regex
   |
help: Replace with `s.split("abc")`
   |
38 | # this should be replaced with `s.split("abc")`
   - re.split("abc", s)
39 + s.split("abc")
40 |
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:71:1
   |
70 |   # this should trigger an unsafe fix because of the presence of comments
71 | / re.sub(
72 | |     # pattern
73 | |     "abc",
74 | |     # repl
75 | |     "",
76 | |     s,  # string
77 | | )
   | |_^
78 |
79 |   # A diagnostic should not be emitted for `sub` replacements with backreferences or
   |
help: Replace with `s.replace("abc", "")`
   |
70 | # this should trigger an unsafe fix because of the presence of comments
   - re.sub(
   -     # pattern
   -     "abc",
   -     # repl
   -     "",
   -     s,  # string
   - )
71 + s.replace("abc", "")
72 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:89:1
   |
87 | # *not* `some_string.replace("a", "\\n")`.
88 | # We currently emit diagnostics for some of these without fixing them.
89 | re.sub(r"a", "\n", "a")
   | ^^^^^^^^^^^^^^^^^^^^^^^
90 | re.sub(r"a", r"\n", "a")
91 | re.sub(r"a", "\a", "a")
   |
help: Replace with `"a".replace(r"a", "\n")`
   |
88 | # We currently emit diagnostics for some of these without fixing them.
   - re.sub(r"a", "\n", "a")
89 + "a".replace(r"a", "\n")
90 | re.sub(r"a", r"\n", "a")
   |

RUF055 Plain string pattern passed to `re` function
  --> RUF055_0.py:90:1
   |
88 | # We currently emit diagnostics for some of these without fixing them.
89 | re.sub(r"a", "\n", "a")
90 | re.sub(r"a", r"\n", "a")
   | ^^^^^^^^^^^^^^^^^^^^^^^^
91 | re.sub(r"a", "\a", "a")
92 | re.sub(r"a", r"\a", "a")
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:91:1
   |
89 | re.sub(r"a", "\n", "a")
90 | re.sub(r"a", r"\n", "a")
91 | re.sub(r"a", "\a", "a")
   | ^^^^^^^^^^^^^^^^^^^^^^^
92 | re.sub(r"a", r"\a", "a")
   |
help: Replace with `"a".replace(r"a", "\x07")`
   |
90 | re.sub(r"a", r"\n", "a")
   - re.sub(r"a", "\a", "a")
91 + "a".replace(r"a", "\x07")
92 | re.sub(r"a", r"\a", "a")
   |

RUF055 Plain string pattern passed to `re` function
  --> RUF055_0.py:92:1
   |
90 | re.sub(r"a", r"\n", "a")
91 | re.sub(r"a", "\a", "a")
92 | re.sub(r"a", r"\a", "a")
   | ^^^^^^^^^^^^^^^^^^^^^^^^
93 |
94 | re.sub(r"a", "\?", "a")
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:94:1
   |
92 | re.sub(r"a", r"\a", "a")
93 |
94 | re.sub(r"a", "\?", "a")
   | ^^^^^^^^^^^^^^^^^^^^^^^
95 | re.sub(r"a", r"\?", "a")
   |
help: Replace with `"a".replace(r"a", "\\?")`
   |
93 |
   - re.sub(r"a", "\?", "a")
94 + "a".replace(r"a", "\\?")
95 | re.sub(r"a", r"\?", "a")
   |

RUF055 [*] Plain string pattern passed to `re` function
  --> RUF055_0.py:95:1
   |
94 | re.sub(r"a", "\?", "a")
95 | re.sub(r"a", r"\?", "a")
   | ^^^^^^^^^^^^^^^^^^^^^^^^
96 |
97 | # these double as tests for preserving raw string quoting style
   |
help: Replace with `"a".replace(r"a", r"\?")`
   |
94 | re.sub(r"a", "\?", "a")
   - re.sub(r"a", r"\?", "a")
95 + "a".replace(r"a", r"\?")
96 |
   |

RUF055 [*] Plain string pattern passed to `re` function
   --> RUF055_0.py:98:1
    |
 97 | # these double as tests for preserving raw string quoting style
 98 | re.sub(r'abc', "", s)
    | ^^^^^^^^^^^^^^^^^^^^^
 99 | re.sub(r"""abc""", "", s)
100 | re.sub(r'''abc''', "", s)
    |
help: Replace with `s.replace(r'abc', "")`
   |
97 | # these double as tests for preserving raw string quoting style
   - re.sub(r'abc', "", s)
98 + s.replace(r'abc', "")
99 | re.sub(r"""abc""", "", s)
   |

RUF055 [*] Plain string pattern passed to `re` function
   --> RUF055_0.py:99:1
    |
 97 | # these double as tests for preserving raw string quoting style
 98 | re.sub(r'abc', "", s)
 99 | re.sub(r"""abc""", "", s)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
100 | re.sub(r'''abc''', "", s)
    |
help: Replace with `s.replace(r"""abc""", "")`
    |
98  | re.sub(r'abc', "", s)
    - re.sub(r"""abc""", "", s)
99  + s.replace(r"""abc""", "")
100 | re.sub(r'''abc''', "", s)
    |

RUF055 [*] Plain string pattern passed to `re` function
   --> RUF055_0.py:100:1
    |
 98 | re.sub(r'abc', "", s)
 99 | re.sub(r"""abc""", "", s)
100 | re.sub(r'''abc''', "", s)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
101 |
102 | # Empty pattern: re.split("", s) should not be flagged because
    |
help: Replace with `s.replace(r'''abc''', "")`
    |
99  | re.sub(r"""abc""", "", s)
    - re.sub(r'''abc''', "", s)
100 + s.replace(r'''abc''', "")
101 |
    |
