| 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 now handles quoted regex patterns to preserve commas within them. | |
| 118 | If the entire value is quoted, it's treated as a single regex pattern. | |
| 119 | Otherwise, it falls back to comma-separated behavior for backward compatibility. | |
| 120 | ||
| 121 | Examples: | |
| 122 | - "(foo{1,3})" -> [re.compile("(foo{1,3})")] # Quoted single pattern | |
| 123 | - "foo, bar" -> [re.compile("foo"), re.compile("bar")] # Traditional CSV | |
| 124 | - '("(a{1,2})","(b{3,4})")' -> [re.compile("(a{1,2})"), re.compile("(b{3,4})")] # Quoted CSV | |
| 125 | """ | |
| 126 | # Check if the input is a single quoted string | |
| 127 | unquoted = pylint_utils._unquote(value) | |
| 128 | if unquoted != value: # The value was quoted | |
| 129 | # Check if the unquoted value is itself a comma-separated list of quoted patterns | |
| 130 | if unquoted.startswith('("') and unquoted.endswith('")') and '","' in unquoted: | |
| 131 | # Handle quoted CSV like '("(pattern1)","(pattern2)")' | |
| 132 | inner_value = unquoted[2:-2] # Remove outer quotes and parentheses | |
| 133 | inner_patterns = inner_value.split('","') | |
| 134 | patterns: list[Pattern[str]] = [] | |
| 135 | for pattern in inner_patterns: | |
| 136 | patterns.append(_regex_transformer(pattern)) | |
| 137 | return patterns | |
| 138 | else: | |
| 139 | # Treat as a single regex pattern | |
| 140 | return [_regex_transformer(unquoted)] | |
| 141 | ||
| 142 | # Fall back to traditional comma-separated behavior | |
| 143 | patterns: list[Pattern[str]] = [] | |
| 144 | for pattern in _csv_transformer(value): | |
| 145 | patterns.append(_regex_transformer(pattern)) | |
| 146 | return patterns | |
| 147 | ||
| 148 | ||
| 149 | def _regexp_csv_smart_transfomer(value: str) -> Sequence[Pattern[str]]: | |
| 150 | """Transforms a comma separated list of regular expressions with smart comma handling. | |
| 151 | ||
| 152 | This function handles both: | |
| 153 | 1. Single quoted regex patterns (preserving commas within quotes) | |
| 154 | 2. Traditional comma-separated lists (for backward compatibility) | |
| 155 | ||
| 156 | Examples: | |
| 157 | - "(foo{1,3})" -> [re.compile("(foo{1,3})")] # Single quoted pattern | |
| 158 | - "foo, bar" -> [re.compile("foo"), re.compile("bar")] # Traditional CSV | |
| 159 | - "(a{1,2}), (b{3,4})" -> [re.compile("(a{1,2})"), re.compile("(b{3,4})")] # Mixed | |
| 160 | """ | |
| 161 | # Check if the input is a single quoted string | |
| 162 | unquoted = pylint_utils._unquote(value) | |
| 163 | if unquoted != value: # The value was quoted | |
| 164 | # Treat as a single regex pattern | |
| 165 | return [_regex_transformer(unquoted)] | |
| 166 | ||
| 167 | # Fall back to traditional comma-separated behavior | |
| 116 | 168 | patterns: list[Pattern[str]] = [] |
| 117 | 169 | for pattern in _csv_transformer(value): |
| 118 | 170 | patterns.append(_regex_transformer(pattern)) |
| 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.