Skip to content

FLY002 autofix with raw strings causes a syntax error #19887

@Spectre5

Description

@Spectre5

Summary

I get an error with the autofix for FLY002 when one (or more) of the strings in the join are a raw string:

$ cat ruff_bug.py
'\n'.join([r'line1','line2'])

$ uvx ruff --version
ruff 0.12.8
$ uvx ruff check ruff_bug.py --no-cache --isolated --fix --unsafe-fixes --select FLY002
Installed 1 package in 1ms

error: Fix introduced a syntax error. Reverting all changes.

This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D

...quoting the contents of `ruff_bug.py`, the rule codes FLY002, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

ruff_bug.py:1:1: FLY002 Consider f-string instead of string join
  |
1 | '\n'.join([r'line1','line2'])
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FLY002
  |
  = help: Replace with f-string

Found 1 error.
[*] 1 fixable with the --fix option.

Version

ruff 0.12.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions