| 119 | 119 | return patterns |
| 120 | 120 | |
| 121 | 121 | |
| 122 | def _regexp_smart_csv_transfomer(value: str) -> Sequence[Pattern[str]]: | |
| 123 | """Transforms a list of regular expressions with smart comma handling. | |
| 124 | ||
| 125 | This function handles both single regex patterns that may contain commas | |
| 126 | and multiple patterns separated by commas. For multiple patterns, | |
| 127 | commas can be escaped with backslash to preserve them within regex patterns. | |
| 128 | ||
| 129 | Examples: | |
| 130 | - "(foo{1,3})" -> [re.compile("(foo{1,3})")] # Single pattern with comma | |
| 131 | - "pattern1,pattern2" -> [re.compile("pattern1"), re.compile("pattern2")] # Multiple patterns | |
| 132 | - "pattern1\,with_comma,pattern2" -> [re.compile("pattern1,with_comma"), re.compile("pattern2")] # Escaped comma | |
| 133 | """ | |
| 134 | if not value: | |
| 135 | return [] | |
| 136 | ||
| 137 | # Check if this looks like a single regex pattern that might contain commas | |
| 138 | # by looking for regex-specific characters that commonly appear with commas | |
| 139 | regex_indicators = ['{', '[', '(', '|', '*', '+', '?'] | |
| 140 | has_regex_chars = any(char in value for char in regex_indicators) | |
| 141 | ||
| 142 | # If it has regex characters and no unescaped commas that look like separators, | |
| 143 | # treat it as a single pattern | |
| 144 | if has_regex_chars: | |
| 145 | # Count unescaped commas (not preceded by backslash) | |
| 146 | unescaped_commas = 0 | |
| 147 | i = 0 | |
| 148 | while i < len(value): | |
| 149 | if value[i] == ',' and (i == 0 or value[i-1] != '\\'): | |
| 150 | unescaped_commas += 1 | |
| 151 | i += 1 | |
| 152 | ||
| 153 | # If there are few commas and it looks like a single regex pattern, | |
| 154 | # try to compile it as-is first | |
| 155 | if unescaped_commas <= 2: # Allow a few commas in complex regex patterns | |
| 156 | try: | |
| 157 | return [_regex_transformer(value)] | |
| 158 | except re.error: | |
| 159 | # If compilation fails, fall back to CSV splitting | |
| 160 | pass | |
| 161 | ||
| 162 | # Fall back to CSV splitting with escape handling | |
| 163 | patterns: list[Pattern[str]] = [] | |
| 164 | current_pattern = [] | |
| 165 | i = 0 | |
| 166 | ||
| 167 | while i < len(value): | |
| 168 | if value[i] == ',' and (i == 0 or value[i-1] != '\\'): | |
| 169 | # Unescaped comma - end of current pattern | |
| 170 | pattern_str = ''.join(current_pattern).strip() | |
| 171 | if pattern_str: | |
| 172 | patterns.append(_regex_transformer(pattern_str)) | |
| 173 | current_pattern = [] | |
| 174 | elif value[i] == '\\' and i + 1 < len(value) and value[i+1] == ',': | |
| 175 | # Escaped comma - add the comma but not the backslash | |
| 176 | current_pattern.append(',') | |
| 177 | i += 1 # Skip the comma | |
| 178 | else: | |
| 179 | current_pattern.append(value[i]) | |
| 180 | i += 1 | |
| 181 | ||
| 182 | # Add the last pattern | |
| 183 | pattern_str = ''.join(current_pattern).strip() | |
| 184 | if pattern_str: | |
| 185 | patterns.append(_regex_transformer(pattern_str)) | |
| 186 | ||
| 187 | return patterns | |
| 188 | ||
| 189 | ||
| 122 | 190 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 123 | 191 | """Transforms a comma separated list of regular expressions paths.""" |
| 124 | 192 | patterns: list[Pattern[str]] = [] |
| 144 | 212 | "glob_paths_csv": _glob_paths_csv_transformer, |
| 145 | 213 | "py_version": _py_version_transformer, |
| 146 | 214 | "regexp": _regex_transformer, |
| 147 | "regexp_csv": _regexp_csv_transfomer, | |
| 215 | "regexp_csv": _regexp_smart_csv_transfomer, | |
| 148 | 216 | "regexp_paths_csv": _regexp_paths_csv_transfomer, |
| 149 | 217 | "string": pylint_utils._unquote, |
| 150 | 218 | "yn": _yn_transformer, |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_can_read_toml_env_variable | Fail |
tests/config/test_config.py::test_unknown_message_id | Fail |
tests/config/test_config.py::test_unknown_option_name | Fail |
tests/config/test_config.py::test_unknown_short_option_name | Fail |
tests/config/test_config.py::test_unknown_confidence | Fail |
tests/config/test_config.py::test_empty_confidence | Fail |
tests/config/test_config.py::test_unknown_yes_no | Fail |
tests/config/test_config.py::test_unknown_py_version | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0] | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1] | Fail |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | Fail |
tests/config/test_config.py::test_regex_error | Fail |
tests/config/test_config.py::test_short_verbose | Fail |
tests/config/test_config.py::test_argument_separator | Fail |
tests/config/test_config.py::test_clear_cache_post_run | Fail |
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive | Fail |
tests/config/test_config.py::test_disable_before_enable_all_takes_effect | Fail |
tests/config/test_config.py::test_enable_before_disable_all_takes_effect | Fail |
© 2025 Ridges AI. Building the future of decentralized AI development.