Skip to content

Commit faa0f81

Browse files
chore: fix inconsistency between lint and format (#18134)
In #18129 it was revealed that lint doesn't check import orderings, but format does. This can result in an issue where code passes the checker, but later fails consistency checks, after running through the formatter This PR adds an extra step to lint to verify import ordering Changes will roll out to generated libraries after the next generation cycle
1 parent 97668d8 commit faa0f81

20 files changed

Lines changed: 164 additions & 2 deletions

File tree

packages/django-google-spanner/noxfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ def lint(session):
8888
"""
8989
session.install("flake8", RUFF_VERSION)
9090

91+
# 1. Check imports
92+
session.run(
93+
"ruff",
94+
"check",
95+
"--select",
96+
"I",
97+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
98+
"--line-length=88",
99+
*LINT_PATHS,
100+
)
101+
91102
# 2. Check formatting
92103
session.run(
93104
"ruff",

packages/gapic-generator/gapic/templates/noxfile.py.j2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ def lint(session):
158158
"""
159159
session.install("flake8", RUFF_VERSION)
160160
161+
# 1. Check imports
162+
session.run(
163+
"ruff", "check",
164+
"--select", "I",
165+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
166+
"--line-length=88",
167+
*LINT_PATHS,
168+
)
169+
161170
# 2. Check formatting
162171
session.run(
163172
"ruff", "format",

packages/gapic-generator/noxfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,17 @@ def lint(session):
760760

761761
session.install("flake8", RUFF_VERSION)
762762

763+
# 1. Check imports
764+
session.run(
765+
"ruff",
766+
"check",
767+
"--select",
768+
"I",
769+
*LINT_PATHS,
770+
"--exclude",
771+
RUFF_EXCLUDES,
772+
)
773+
763774
# 2. Check formatting
764775
session.run(
765776
"ruff",

packages/gapic-generator/tests/integration/goldens/asset/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

packages/gapic-generator/tests/integration/goldens/logging/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

packages/gapic-generator/tests/integration/goldens/redis/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def lint(session):
161161
"""
162162
session.install("flake8", RUFF_VERSION)
163163

164+
# 1. Check imports
165+
session.run(
166+
"ruff", "check",
167+
"--select", "I",
168+
f"--target-version=py{ALL_PYTHON[0].replace('.', '')}",
169+
"--line-length=88",
170+
*LINT_PATHS,
171+
)
172+
164173
# 2. Check formatting
165174
session.run(
166175
"ruff", "format",

0 commit comments

Comments
 (0)