| 53 | 53 | return pylint_utils._check_csv(value) |
| 54 | 54 | |
| 55 | 55 | |
| 56 | def _csv_transformer_with_quotes(value: str) -> Sequence[str]: | |
| 57 | """Transforms a comma separated string, respecting quoted strings. | |
| 58 | ||
| 59 | This function splits on commas but treats commas inside quoted strings | |
| 60 | (single or double quotes) as part of the content, not as separators. | |
| 61 | ||
| 62 | Examples: | |
| 63 | "pattern1, pattern2" -> ["pattern1", "pattern2"] | |
| 64 | "pattern1, \"pattern2,with,commas\"" -> ["pattern1", "pattern2,with,commas"] | |
| 65 | "'pattern1,with,commas', pattern2" -> ["pattern1,with,commas", "pattern2"] | |
| 66 | """ | |
| 67 | if isinstance(value, (list, tuple)): | |
| 68 | return value | |
| 69 | ||
| 70 | result = [] | |
| 71 | current = [] | |
| 72 | in_quotes = False | |
| 73 | quote_char = None | |
| 74 | i = 0 | |
| 75 | ||
| 76 | while i < len(value): | |
| 77 | char = value[i] | |
| 78 | ||
| 79 | if char in "\"'" and not in_quotes: | |
| 80 | # Start of quoted string | |
| 81 | in_quotes = True | |
| 82 | quote_char = char | |
| 83 | elif char == quote_char and in_quotes: | |
| 84 | # End of quoted string | |
| 85 | in_quotes = False | |
| 86 | quote_char = None | |
| 87 | elif char == ',' and not in_quotes: | |
| 88 | # Comma separator outside quotes | |
| 89 | result.append(''.join(current).strip()) | |
| 90 | current = [] | |
| 91 | i += 1 | |
| 92 | continue | |
| 93 | ||
| 94 | current.append(char) | |
| 95 | i += 1 | |
| 96 | ||
| 97 | # Add the last item | |
| 98 | if current: | |
| 99 | result.append(''.join(current).strip()) | |
| 100 | ||
| 101 | # Remove empty strings and strip quotes from individual items | |
| 102 | cleaned_result = [] | |
| 103 | for item in result: | |
| 104 | # Remove surrounding quotes if present | |
| 105 | if (len(item) >= 2 and | |
| 106 | ((item[0] == '"' and item[-1] == '"') or | |
| 107 | (item[0] == "'" and item[-1] == "'"))): | |
| 108 | item = item[1:-1] | |
| 109 | # Only add non-empty items | |
| 110 | if item.strip() or item: | |
| 111 | cleaned_result.append(item) | |
| 112 | ||
| 113 | return cleaned_result | |
| 114 | ||
| 115 | return cleaned_result | |
| 116 | ||
| 117 | ||
| 56 | 118 | YES_VALUES = {"y", "yes", "true"} |
| 57 | 119 | NO_VALUES = {"n", "no", "false"} |
| 58 | 120 | |
| 112 | 174 | |
| 113 | 175 | |
| 114 | 176 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 177 | """Transforms a comma separated list of regular expressions. | |
| 178 | ||
| 179 | Supports quoted strings to allow commas within regex patterns. | |
| 180 | For example: "pattern1, pattern2" or "pattern1, \"pattern2,with,commas\"" | |
| 181 | """ | |
| 116 | 182 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 183 | for pattern in _csv_transformer_with_quotes(value): | |
| 118 | 184 | patterns.append(_regex_transformer(pattern)) |
| 119 | 185 | return patterns |
| 120 | 186 |
| 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.