Skip to content

Commit a5a66f2

Browse files
committed
Add optional ruff check --fix support to ruff-format target
Introduces RUFF_FIXES and RUFF_UNSAFE_FIXES settings to enable auto-fixing linting issues. Default is false (non-breaking). Echo output shows actual flags used for transparency. Addresses #61
1 parent c075006 commit a5a66f2

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/mxmake/tests/test_topics.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ def test_get_domain(self):
8686
domain = topics.get_domain("core.mxenv")
8787
self.assertEqual(domain.fqn, "core.mxenv")
8888

89+
def test_ruff_domain_settings(self):
90+
"""Test ruff domain has correct settings for check --fix feature."""
91+
domain = topics.get_domain("qa.ruff")
92+
self.assertEqual(domain.fqn, "qa.ruff")
93+
94+
settings = {s.name: s for s in domain.settings}
95+
96+
# Verify RUFF_FIXES setting
97+
self.assertIn("RUFF_FIXES", settings)
98+
ruff_fixes = settings["RUFF_FIXES"]
99+
self.assertEqual(ruff_fixes.default, "false")
100+
self.assertIn("ruff check --fix", ruff_fixes.description)
101+
102+
# Verify RUFF_UNSAFE_FIXES setting
103+
self.assertIn("RUFF_UNSAFE_FIXES", settings)
104+
ruff_unsafe = settings["RUFF_UNSAFE_FIXES"]
105+
self.assertEqual(ruff_unsafe.default, "false")
106+
self.assertIn("unsafe fixes", ruff_unsafe.description)
107+
108+
# Verify RUFF_SRC setting still exists
109+
self.assertIn("RUFF_SRC", settings)
110+
89111
@testing.temp_directory
90112
def test_Domain(self, tmpdir):
91113
domain_path = tmpdir / "domain.mk"

src/mxmake/topics/qa/ruff.mk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@
66
#:[target.ruff]
77
#:description = Run ruff.
88
#:
9+
#:[target.ruff-format]
10+
#:description = Run ruff format. Optionally apply fixes with RUFF_FIXES=true.
11+
#:
912
#:[setting.RUFF_SRC]
1013
#:description = Source folder to scan for Python files to run ruff on.
1114
#:default = src
1215
#:
16+
#:[setting.RUFF_FIXES]
17+
#:description = Enable ruff check --fix when running ruff-format.
18+
#: Set to `true` to enable automatic fixes.
19+
#:default = false
20+
#:
21+
#:[setting.RUFF_UNSAFE_FIXES]
22+
#:description = Enable unsafe fixes when RUFF_FIXES is enabled.
23+
#: Set to `true` to enable unsafe fixes.
24+
#:default = false
25+
#:
1326
#:[target.ruff-dirty]
1427
#:description = Marks ruff dirty
1528
#:
@@ -25,6 +38,15 @@ ifeq ($(RUFF_SRC),src)
2538
RUFF_SRC:=$(PYTHON_PROJECT_PREFIX)src
2639
endif
2740

41+
# Build ruff check flags based on settings
42+
ifeq ("$(RUFF_FIXES)","true")
43+
ifeq ("$(RUFF_UNSAFE_FIXES)","true")
44+
RUFF_FIX_FLAGS=--fix --unsafe-fixes
45+
else
46+
RUFF_FIX_FLAGS=--fix
47+
endif
48+
endif
49+
2850
RUFF_TARGET:=$(SENTINEL_FOLDER)/ruff.sentinel
2951
$(RUFF_TARGET): $(MXENV_TARGET)
3052
@echo "Install Ruff"
@@ -40,6 +62,10 @@ ruff-check: $(RUFF_TARGET)
4062
ruff-format: $(RUFF_TARGET)
4163
@echo "Run ruff format"
4264
@ruff format $(RUFF_SRC)
65+
ifeq ("$(RUFF_FIXES)","true")
66+
@echo "Run ruff check $(RUFF_FIX_FLAGS)"
67+
@ruff check $(RUFF_FIX_FLAGS) $(RUFF_SRC)
68+
endif
4369

4470
.PHONY: ruff-dirty
4571
ruff-dirty:

0 commit comments

Comments
 (0)