| 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 | Supports quoted patterns to allow commas within regex patterns. | |
| 118 | For example: "pattern1", "(foo{1,3})", "pattern3" | |
| 119 | """ | |
| 116 | 120 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 121 | for pattern in _split_csv_with_quotes(value): | |
| 118 | 122 | patterns.append(_regex_transformer(pattern)) |
| 119 | 123 | return patterns |
| 120 | 124 | |
| 121 | 125 | |
| 126 | def _split_csv_with_quotes(value: str) -> Sequence[str]: | |
| 127 | """Split a CSV string while respecting quoted strings. | |
| 128 | ||
| 129 | This function handles CSV parsing where fields can be quoted | |
| 130 | to include commas within the field content. | |
| 131 | ||
| 132 | Examples: | |
| 133 | "pattern1,pattern2" -> ["pattern1", "pattern2"] | |
| 134 | "pattern1,\"(foo{1,3})\",pattern3" -> ["pattern1", "(foo{1,3})", "pattern3"] | |
| 135 | "\'(foo{1,3})\'" -> ["(foo{1,3})"] | |
| 136 | ||
| 137 | :param value: The CSV string to split | |
| 138 | :return: List of split and unquoted fields | |
| 139 | """ | |
| 140 | if not value: | |
| 141 | return [] | |
| 142 | ||
| 143 | result: list[str] = [] | |
| 144 | current_field = [] | |
| 145 | in_quotes = False | |
| 146 | quote_char = None | |
| 147 | i = 0 | |
| 148 | ||
| 149 | while i < len(value): | |
| 150 | char = value[i] | |
| 151 | ||
| 152 | if not in_quotes: | |
| 153 | if char in ('"', "'"): | |
| 154 | # Start of quoted field | |
| 155 | in_quotes = True | |
| 156 | quote_char = char | |
| 157 | elif char == ',': | |
| 158 | # Field separator | |
| 159 | field = ''.join(current_field).strip() | |
| 160 | if field: # Skip empty fields | |
| 161 | result.append(pylint_utils._unquote(field)) | |
| 162 | current_field = [] | |
| 163 | else: | |
| 164 | current_field.append(char) | |
| 165 | else: | |
| 166 | if char == quote_char and i > 0 and value[i-1] != '\\': | |
| 167 | # End of quoted field (not escaped) | |
| 168 | in_quotes = False | |
| 169 | quote_char = None | |
| 170 | else: | |
| 171 | current_field.append(char) | |
| 172 | ||
| 173 | i += 1 | |
| 174 | ||
| 175 | # Add the last field | |
| 176 | field = ''.join(current_field).strip() | |
| 177 | if field: # Skip empty fields | |
| 178 | result.append(pylint_utils._unquote(field)) | |
| 179 | ||
| 180 | return result | |
| 181 | ||
| 182 | ||
| 122 | 183 | def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 123 | 184 | """Transforms a comma separated list of regular expressions paths.""" |
| 124 | 185 | patterns: list[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.