File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -27,11 +27,16 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
27
27
if dep .startswith (f"{ tool } ==" ):
28
28
return dep .split ("==" )[1 ]
29
29
30
+ # Fallback to project.dependencies for backward compatibility
31
+ dependencies = data .get ("project" , {}).get ("dependencies" , [])
32
+ for dep in dependencies :
33
+ if dep .startswith (f"{ tool } ==" ):
34
+ return dep .split ("==" )[1 ]
30
35
return None
31
36
32
37
33
- DEFAULT_CLANG_FORMAT_VERSION = get_version_from_dependency ("clang-format" )
34
- DEFAULT_CLANG_TIDY_VERSION = get_version_from_dependency ("clang-tidy" )
38
+ DEFAULT_CLANG_FORMAT_VERSION = get_version_from_dependency ("clang-format" ) or "20.1.7"
39
+ DEFAULT_CLANG_TIDY_VERSION = get_version_from_dependency ("clang-tidy" ) or "20.1.0"
35
40
36
41
37
42
CLANG_FORMAT_VERSIONS = [
@@ -179,6 +184,10 @@ def _resolve_install(tool: str, version: Optional[str]) -> Optional[Path]:
179
184
else DEFAULT_CLANG_TIDY_VERSION
180
185
)
181
186
187
+ # Additional safety check in case DEFAULT versions are None
188
+ if user_version is None :
189
+ user_version = "20.1.7" if tool == "clang-format" else "20.1.0"
190
+
182
191
path = shutil .which (tool )
183
192
if path :
184
193
runtime_version = _get_runtime_version (tool )
Original file line number Diff line number Diff line change @@ -427,3 +427,22 @@ def test_version_lists_not_empty():
427
427
assert len (CLANG_TIDY_VERSIONS ) > 0
428
428
assert all (isinstance (v , str ) for v in CLANG_FORMAT_VERSIONS )
429
429
assert all (isinstance (v , str ) for v in CLANG_TIDY_VERSIONS )
430
+
431
+
432
+ @pytest .mark .benchmark
433
+ def test_resolve_install_with_none_default_version ():
434
+ """Test _resolve_install when DEFAULT versions are None."""
435
+ with (
436
+ patch ("shutil.which" , return_value = None ),
437
+ patch ("cpp_linter_hooks.util.DEFAULT_CLANG_FORMAT_VERSION" , None ),
438
+ patch ("cpp_linter_hooks.util.DEFAULT_CLANG_TIDY_VERSION" , None ),
439
+ patch (
440
+ "cpp_linter_hooks.util._install_tool" ,
441
+ return_value = Path ("/usr/bin/clang-format" ),
442
+ ) as mock_install ,
443
+ ):
444
+ result = _resolve_install ("clang-format" , None )
445
+ assert result == Path ("/usr/bin/clang-format" )
446
+
447
+ # Should fallback to hardcoded version when DEFAULT is None
448
+ mock_install .assert_called_once_with ("clang-format" , "20.1.7" )
You can’t perform that action at this time.
0 commit comments