Fixed: "E501 Line too long (107 > 100)" in Ruff After ruff format
ruff check stopped on one line of a small script: E501 Line too long (123 > 100). Running ruff format changed the file but not the verdict: E501 Line too long (107 > 100). The line was a long SQL string, and the formatter doesn't split strings. Here's how I worked that out, and the fix, with real output from Ruff 0.17.6.
What I Was Doing
I was writing an example script that creates a SQLite table, in a uv project that checks its code with Ruff. The project's pyproject.toml allows lines of up to 100 characters and turns on the E and F rules:
[tool.ruff]
line-length = 100
[tool.ruff.lint]
select = ["E", "F"]
The script puts the whole CREATE TABLE statement in one string:
import sqlite3
connection = sqlite3.connect(":memory:")
connection.execute("CREATE TABLE items (quantity INTEGER, price REAL, name TEXT, note TEXT, photo BLOB, in_stock INTEGER)")
print("Table created.")
What I Expected
All checks passed!
What I Got
uv run ruff check
E501 Line too long (123 > 100)
--> items_table.py:4:101
|
3 | connection = sqlite3.connect(":memory:")
4 | connection.execute("CREATE TABLE items (quantity INTEGER, price REAL, name TEXT, note TEXT, photo BLOB, in_stock INTEGER)")
| ^^^^^^^^^^^^^^^^^^^^^^^
5 | print("Table created.")
|
Found 1 error.

Line 4 is 123 characters long, and the carets mark everything past column 100.
What I Checked
1. What E501 checks. Ruff's E501 rule page: it "Checks for lines that exceed the specified maximum character length." Its default is 88 characters, "though that limit is configurable via the line-length setting." This project sets 100, so 123 is over.
2. Whether ruff's default rules include it. They don't. uv run ruff check --isolated --line-length 100 items_table.py, which ignores the project's settings, printed All checks passed! for the same file. E501 runs here because the project selects the E rules.
3. Whether ruff format fixes it. The formatter wraps long lines, so I ran it, then checked again:
uv run ruff format
uv run ruff check
1 file reformatted
E501 Line too long (107 > 100)
--> items_table.py:5:101
|
3 | connection = sqlite3.connect(":memory:")
4 | connection.execute(
5 | "CREATE TABLE items (quantity INTEGER, price REAL, name TEXT, note TEXT, photo BLOB, in_stock INTEGER)"
| ^^^^^^^
6 | )
7 | print("Table created.")
|
Found 1 error.

The formatter moved the string onto its own line, but left the string whole, and that line alone is 107 characters. Ruff's line-length setting says as much: "While the formatter will attempt to format lines such that they remain within the line-length, it isn't a hard upper bound, and formatted lines may exceed the line-length."
Why It Happens
The SQL string is 103 characters with its quotes. Indented by 4 spaces it's 107, whatever the formatter does around it. Ruff's formatter changes the layout of code, but it doesn't cut a string in two, so the line can't get under 100 without a change to the string itself.
The Fix
Split the string into two strings, side by side inside the parentheses. Python joins adjacent string literals into one. Its language reference: "Multiple adjacent string or bytes literals, possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation".
import sqlite3
connection = sqlite3.connect(":memory:")
connection.execute(
"CREATE TABLE items (quantity INTEGER, price REAL, name TEXT,"
" note TEXT, photo BLOB, in_stock INTEGER)"
)
print("Table created.")

- The first part ends after
name TEXT,, the second starts with a space, so the joined SQL is exactly the original statement. - No
+is needed: the two strings are joined when Python reads the file.
After the Fix
uv run ruff check
uv run python items_table.py
All checks passed!
Table created.

Ruff passed, and the script still created the table. uv run ruff format --check printed 1 file already formatted, so the formatter keeps the split as it is.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting ruff format to fix every E501 | It doesn't split strings: the error stayed, at (107 > 100) | Split the long string yourself |
Splitting with no space at the join, "... name" "TEXT, ..." | No error at all: SQLite created a column called nameTEXT with no type | Keep the space, at the end of one part or the start of the next |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
E501 is still reported after ruff format | The line holds a string longer than the limit | Split the string into adjacent literals |
| E501 appears in one project but not another | Only projects that select the E rules run it | Check [tool.ruff.lint] in pyproject.toml |
FAQ
Can I allow one long line instead?
Yes. A # noqa: E501 comment at the end of the line tells Ruff to skip it: with it, ruff check printed All checks passed! for the original line. Use it for lines that really can't be split.
Why does the message show two numbers?
The first is the line's length, the second the limit: (123 > 100) is a 123-character line in a project that allows 100.
Conclusion
The long SQL string kept its line at 107 characters even after ruff format, because the formatter doesn't split strings. Splitting it into two adjacent literals brought every line under 100, and ruff check passed.
Additional Resources
- line-too-long (E501) — what the rule checks and the lines it ignores.
- line-length — the setting, and why formatted lines can still exceed it.
- String literal concatenation — adjacent strings joined into one.
