Skip to content

Commit b2f3c63

Browse files
authored
Hides regex compilation warning (#6657)
Suppresses a FutureWarning related to regex compilation to prevent unnecessary noise in the logs. This improves the user experience by reducing irrelevant warnings.
1 parent 0eac80b commit b2f3c63

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
2727

2828
- Fixes
2929
- [#6544](https://github.com/oxsecurity/megalinter/issues/6544): Add GITHUB_TOKEN in docker build command for custom flavor
30+
- Hide warning when compiling a regex
3031

3132
- Reporters
3233

megalinter/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88
import tempfile
99
import urllib.parse
10+
import warnings
1011
from fnmatch import fnmatch
1112
from pathlib import Path
1213
from typing import Any, Optional, Pattern, Sequence
@@ -640,7 +641,9 @@ def keep_only_valid_regex_patterns(patterns, fail=False):
640641
# First, attempt to fix the pattern
641642
fixed_pattern = fix_regex_pattern(pattern)
642643
try:
643-
re.compile(fixed_pattern) # Check if the pattern is valid
644+
with warnings.catch_warnings():
645+
warnings.simplefilter("ignore", FutureWarning)
646+
re.compile(fixed_pattern) # Check if the pattern is valid
644647
# Skip if pattern has nested quantifiers (ReDoS risk)
645648
if nested_quantifier_regex.search(fixed_pattern):
646649
logging.debug(

0 commit comments

Comments
 (0)