Enable rules with given names. :param names: name or list of rule names to enable. :param ignoreInvalid: ignore errors when rule not found :raises: KeyError if name not found and not ignoreInvalid :return: list of found rule names
(
self, names: str | Iterable[str], ignoreInvalid: bool = False
)
| 189 | self.__cache__ = None |
| 190 | |
| 191 | def enable( |
| 192 | self, names: str | Iterable[str], ignoreInvalid: bool = False |
| 193 | ) -> list[str]: |
| 194 | """Enable rules with given names. |
| 195 | |
| 196 | :param names: name or list of rule names to enable. |
| 197 | :param ignoreInvalid: ignore errors when rule not found |
| 198 | :raises: KeyError if name not found and not ignoreInvalid |
| 199 | :return: list of found rule names |
| 200 | """ |
| 201 | if isinstance(names, str): |
| 202 | names = [names] |
| 203 | result: list[str] = [] |
| 204 | for name in names: |
| 205 | idx = self.__find__(name) |
| 206 | if (idx < 0) and ignoreInvalid: |
| 207 | continue |
| 208 | if (idx < 0) and not ignoreInvalid: |
| 209 | raise KeyError(f"Rules manager: invalid rule name {name}") |
| 210 | self.__rules__[idx].enabled = True |
| 211 | result.append(name) |
| 212 | self.__cache__ = None |
| 213 | return result |
| 214 | |
| 215 | def enableOnly( |
| 216 | self, names: str | Iterable[str], ignoreInvalid: bool = False |