Skip to content

Commit f779a8c

Browse files
committed
chore: add ruff
1 parent a6ad6a2 commit f779a8c

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

packages/google-cloud-firestore/noxfile.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@
3131

3232
import nox
3333

34+
RUFF_VERSION = "ruff==0.14.14"
3435
FLAKE8_VERSION = "flake8==6.1.0"
3536
PYTYPE_VERSION = "pytype==2020.7.24"
3637
BLACK_VERSION = "black[jupyter]==23.7.0"
3738
ISORT_VERSION = "isort==5.11.0"
3839
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3940

41+
# Add samples to the list of directories to format if the directory exists.
42+
if os.path.isdir("samples"):
43+
LINT_PATHS.append("samples")
44+
4045
ALL_PYTHON = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
4146
DEFAULT_PYTHON_VERSION = "3.14"
4247

@@ -136,19 +141,31 @@ def blacken(session):
136141
@nox.session(python=DEFAULT_PYTHON_VERSION)
137142
def format(session):
138143
"""
139-
Run isort to sort imports. Then run black
140-
to format code to uniform standard.
144+
Run ruff to sort imports and format code.
141145
"""
142-
session.install(BLACK_VERSION, ISORT_VERSION)
143-
# Use the --fss option to sort imports using strict alphabetical order.
144-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
146+
# 1. Install ruff (skipped automatically if you run with --no-venv)
147+
session.install(RUFF_VERSION)
148+
149+
# 2. Run Ruff to fix imports
150+
# check --select I: Enables strict import sorting
151+
# --fix: Applies the changes automatically
145152
session.run(
146-
"isort",
147-
"--fss",
153+
"ruff",
154+
"check",
155+
"--select",
156+
"I",
157+
"--fix",
158+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
159+
"--line-length=88", # Standard Black line length
148160
*LINT_PATHS,
149161
)
162+
163+
# 3. Run Ruff to format code
150164
session.run(
151-
"black",
165+
"ruff",
166+
"format",
167+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
168+
"--line-length=88", # Standard Black line length
152169
*LINT_PATHS,
153170
)
154171

0 commit comments

Comments
 (0)