| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 115 | """Transforms a comma separated list of regular expressions. | |
| 116 | ||
| 117 | This function intelligently handles regex patterns containing commas: | |
| 118 | - Patterns with regex syntax that uses commas (like {n,m}) are treated as single patterns | |
| 119 | - Simple comma-separated patterns are split for backward compatibility | |
| 120 | ||
| 121 | Examples: | |
| 122 | - "pattern1,pattern2" -> [pattern1, pattern2] (backward compatibility) | |
| 123 | - "(foo{1,3})" -> [(foo{1,3})] (single pattern with comma) | |
| 124 | - "pattern1,(foo{1,3}),pattern2" -> [pattern1, (foo{1,3}), pattern2] (mixed) | |
| 125 | """ | |
| 126 | if not value: | |
| 127 | return [] | |
| 128 | ||
| 129 | # Check if this looks like a single pattern with regex syntax that uses commas | |
| 130 | # Common case: quantifiers like {1,3} | |
| 131 | if '{' in value and ',' in value: | |
| 132 | # Look for patterns like {n,m} where n and m are numbers | |
| 133 | import re as regex_mod | |
| 134 | if regex_mod.search(r'\{\d*,\d*\}', value) or regex_mod.search(r'\{\d+,\s*\d*\}', value): | |
| 135 | # This looks like it contains quantifier syntax, treat as single pattern | |
| 136 | try: | |
| 137 | pattern = _regex_transformer(value) | |
| 138 | return [pattern] | |
| 139 | except (re.error, argparse.ArgumentTypeError): | |
| 140 | # If it fails, fall through to normal processing | |
| 141 | pass | |
| 142 | ||
| 143 | # Try normal comma-separated processing for backward compatibility | |
| 144 | split_parts = pylint_utils._check_csv(value) | |
| 116 | 145 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | return patterns | |
| 146 | split_compilation_failed = False | |
| 147 | ||
| 148 | # Try to compile each split part | |
| 149 | for pattern_str in split_parts: | |
| 150 | try: | |
| 151 | patterns.append(_regex_transformer(pattern_str)) | |
| 152 | except (re.error, argparse.ArgumentTypeError): | |
| 153 | split_compilation_failed = True | |
| 154 | break | |
| 155 | ||
| 156 | # If all parts compiled successfully, return them | |
| 157 | if not split_compilation_failed: | |
| 158 | return patterns | |
| 159 | ||
| 160 | # If compilation failed, try treating the entire string as a single pattern | |
| 161 | try: | |
| 162 | pattern = _regex_transformer(value) | |
| 163 | return [pattern] | |
| 164 | except (re.error, argparse.ArgumentTypeError): | |
| 165 | # If that also fails, re-raise the original error from the split attempt | |
| 166 | # Try again to get the proper error message | |
| 167 | patterns = [] | |
| 168 | for pattern_str in split_parts: | |
| 169 | patterns.append(_regex_transformer(pattern_str)) | |
| 170 | return patterns # This line should never be reached due to the exception above | |
| 120 | 171 | |
| 121 | 172 | |
| 122 | 173 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | Fail |
tests/config/test_config.py::test_can_read_toml_env_variable | Pass |
tests/config/test_config.py::test_unknown_message_id | Pass |
tests/config/test_config.py::test_unknown_option_name | Pass |
tests/config/test_config.py::test_unknown_short_option_name | Pass |
tests/config/test_config.py::test_unknown_confidence | Pass |
tests/config/test_config.py::test_empty_confidence | Pass |
tests/config/test_config.py::test_unknown_yes_no | Pass |
tests/config/test_config.py::test_unknown_py_version | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1] | Pass |
tests/config/test_config.py::test_regex_error | Pass |
tests/config/test_config.py::test_short_verbose | Pass |
tests/config/test_config.py::test_argument_separator | Pass |
tests/config/test_config.py::test_clear_cache_post_run | Pass |
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive | Pass |
tests/config/test_config.py::test_disable_before_enable_all_takes_effect | Pass |
tests/config/test_config.py::test_enable_before_disable_all_takes_effect | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.