Skip to content

Commit 8efa393

Browse files
committed
Switch from flake8 to ruff.
1 parent 0e9b42d commit 8efa393

20 files changed

Lines changed: 142 additions & 240 deletions

.flake8

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Before submitting your pull request please have a look at the
44
following checklist:
55

66
- [ ] ran the tests (`pytest`)
7-
- [ ] all style issues addressed (`flake8`)
7+
- [ ] all style issues addressed (`ruff`)
88
- [ ] your changes are covered by tests
99
- [ ] your changes are documented, if needed
1010

.github/workflows/python-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353

5454
- name: Run lint (Python 3.11 only)
5555
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
56-
run: uv run --group dev flake8 sqlparse/
56+
run: uv run --group dev ruff check sqlparse/
5757

5858
- name: Generate coverage report (Python 3.11 only)
5959
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This project uses `uv` for dependency and environment management. Common command
1818
- Using Makefile: `make test`
1919

2020
### Linting
21-
- `uv run --group dev flake8 sqlparse/` or `make lint`
21+
- `uv run --group dev ruff check sqlparse/` or `make lint`
2222

2323
### Coverage
2424
- `make coverage` (runs tests with coverage and shows report)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test:
1919
uv run --group dev --python 3.14 pytest tests/
2020

2121
lint:
22-
uv run --group dev flake8 sqlparse/
22+
uv run --group dev ruff check sqlparse/
2323

2424
coverage:
2525
uv run --group dev coverage run -m pytest tests/

pyproject.toml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,44 @@ exclude_lines = [
7373
dev = [
7474
"pytest",
7575
"coverage",
76-
"flake8",
76+
"ruff",
7777
"build",
7878
"sphinx",
7979
]
8080

81+
[tool.ruff]
82+
target-version = "py38"
83+
exclude = [
84+
"dist",
85+
"docs",
86+
"tests",
87+
]
88+
89+
[tool.ruff.lint]
90+
select = [
91+
"E", # pycodestyle errors
92+
"F", # Pyflakes
93+
"W", # pycodestyle warnings
94+
"C90", # mccabe complexity
95+
"B", # flake8-bugbear (bugs/design issues)
96+
"I", # isort (import sorting)
97+
"UP", # pyupgrade (modern python syntax)
98+
"SIM", # flake8-simplify (simpler code)
99+
"RUF", # Ruff-specific rules
100+
]
101+
ignore = [
102+
"RUF001", # Ambiguous unicode character (acute accent is used intentionally for quoting)
103+
"RUF012", # Mutable default value for class attribute (used for SQL matching patterns)
104+
"B904", # raise ... from ... (not required for simple custom exceptions)
105+
"E501", # Line too long (managed by formatting choices rather than strict rules)
106+
"SIM108", # Use ternary operator instead of if-else block (traditional if-else is preferred for readability)
107+
"RUF005", # Consider iterable unpacking instead of concatenation
108+
"RUF059", # Unused unpacked variables (retains standard unpacking signatures)
109+
"SIM102", # Nested if statements (sometimes preferred for logic separation)
110+
"SIM115", # Use a context manager for opening files (CLI streams are opened dynamically)
111+
]
112+
113+
[tool.ruff.lint.mccabe]
114+
max-complexity = 31
115+
116+

sqlparse/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88
"""Parse SQL statements."""
99

1010
# Setup namespace
11-
from typing import Any, Generator, IO, List, Optional, Tuple, Union
12-
13-
from sqlparse import sql
14-
from sqlparse import cli
15-
from sqlparse import engine
16-
from sqlparse import tokens
17-
from sqlparse import filters
18-
from sqlparse import formatter
11+
from typing import IO, Any, Generator, List, Optional, Tuple, Union
1912

13+
from sqlparse import cli, engine, filters, formatter, sql, tokens
2014

2115
__version__ = "0.5.6.dev0"
22-
__all__ = ["engine", "filters", "formatter", "sql", "tokens", "cli"]
16+
__all__ = ["cli", "engine", "filters", "formatter", "sql", "tokens"]
2317

2418

2519
def parse(

sqlparse/engine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sqlparse.engine.statement_splitter import StatementSplitter
1111

1212
__all__ = [
13-
'grouping',
1413
'FilterStack',
1514
'StatementSplitter',
15+
'grouping',
1616
]

sqlparse/engine/grouping.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sqlparse import sql
99
from sqlparse import tokens as T
1010
from sqlparse.exceptions import SQLParseError
11-
from sqlparse.utils import recurse, imt
11+
from sqlparse.utils import imt, recurse
1212

1313
# Maximum recursion depth for grouping operations to prevent DoS attacks
1414
# Set to None to disable limit (not recommended for untrusted input)
@@ -234,12 +234,7 @@ def match(token):
234234
return token.ttype == T.Operator.Comparison
235235

236236
def valid(token):
237-
if imt(token, t=ttypes, i=sqlcls):
238-
return True
239-
elif token and token.is_keyword and token.normalized == 'NULL':
240-
return True
241-
else:
242-
return False
237+
return bool(imt(token, t=ttypes, i=sqlcls) or (token and token.is_keyword and token.normalized == 'NULL'))
243238

244239
def post(tlist, pidx, tidx, nidx):
245240
return pidx, nidx

sqlparse/engine/statement_splitter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# This module is part of python-sqlparse and is released under
66
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
77

8-
from sqlparse import sql, tokens as T
8+
from sqlparse import sql
9+
from sqlparse import tokens as T
910

1011

1112
class StatementSplitter:

0 commit comments

Comments
 (0)