| 111 | 111 | raise argparse.ArgumentTypeError(msg) from e |
| 112 | 112 | |
| 113 | 113 | |
| 114 | def _quoted_csv_transformer(value: str) -> Sequence[str]: | |
| 115 | """Transforms a comma separated string, respecting quoted strings and regex patterns. | |
| 116 | ||
| 117 | This function allows commas within quoted strings and attempts to detect | |
| 118 | when commas are part of regex patterns (e.g., quantifiers like {1,3}). | |
| 119 | """ | |
| 120 | result = [] | |
| 121 | current = "" | |
| 122 | in_quotes = False | |
| 123 | quote_char = None | |
| 124 | brace_depth = 0 # Track depth of curly braces for regex quantifiers | |
| 125 | bracket_depth = 0 # Track depth of square brackets for character classes | |
| 126 | paren_depth = 0 # Track depth of parentheses for groups | |
| 127 | i = 0 | |
| 128 | ||
| 129 | while i < len(value): | |
| 130 | char = value[i] | |
| 131 | ||
| 132 | if not in_quotes and char in "\"'": | |
| 133 | in_quotes = True | |
| 134 | quote_char = char | |
| 135 | elif in_quotes and char == quote_char: | |
| 136 | # Check for escaped quote | |
| 137 | if i + 1 < len(value) and value[i + 1] == quote_char: | |
| 138 | current += char | |
| 139 | i += 1 # Skip next quote | |
| 140 | else: | |
| 141 | in_quotes = False | |
| 142 | quote_char = None | |
| 143 | elif not in_quotes: | |
| 144 | # Track regex construct depths | |
| 145 | if char == "{": | |
| 146 | brace_depth += 1 | |
| 147 | elif char == "}": | |
| 148 | brace_depth = max(0, brace_depth - 1) | |
| 149 | elif char == "[": | |
| 150 | bracket_depth += 1 | |
| 151 | elif char == "]": | |
| 152 | bracket_depth = max(0, bracket_depth - 1) | |
| 153 | elif char == "(": | |
| 154 | paren_depth += 1 | |
| 155 | elif char == ")": | |
| 156 | paren_depth = max(0, paren_depth - 1) | |
| 157 | elif char == "," and brace_depth == 0 and bracket_depth == 0 and paren_depth == 0: | |
| 158 | # Only split on comma if we're not inside any regex construct | |
| 159 | result.append(current.strip()) | |
| 160 | current = "" | |
| 161 | i += 1 | |
| 162 | continue | |
| 163 | ||
| 164 | current += char | |
| 165 | i += 1 | |
| 166 | ||
| 167 | # Add the last item | |
| 168 | if current or value.endswith(","): | |
| 169 | result.append(current.strip()) | |
| 170 | ||
| 171 | # Remove empty strings and unquote each item | |
| 172 | return [pylint_utils._unquote(item) for item in result if item] | |
| 173 | ||
| 174 | ||
| 114 | 175 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | """Transforms a comma separated list of regular expressions.""" | |
| 176 | """Transforms a comma separated list of regular expressions. | |
| 177 | ||
| 178 | This function supports commas within quoted regex patterns. | |
| 179 | For example: "(foo{1,3})",bar will be parsed as two patterns: | |
| 180 | - (foo{1,3}) - a regex with a quantifier containing a comma | |
| 181 | - bar - a simple regex | |
| 182 | """ | |
| 116 | 183 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 184 | for pattern in _quoted_csv_transformer(value): | |
| 118 | 185 | patterns.append(_regex_transformer(pattern)) |
| 119 | 186 | return patterns |
| 120 | 187 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | 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_csv_regex_comma_in_quantifier[foo, | 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.