|
34 | 34 |
|
35 | 35 | MSG_TYPES_DOC = {k: v if v != "info" else "information" for k, v in MSG_TYPES.items()} |
36 | 36 |
|
| 37 | +MESSAGES_WITHOUT_EXAMPLES = { |
| 38 | + "astroid-error", # internal |
| 39 | + "bad-configuration-section", # configuration |
| 40 | + "bad-plugin-value", # internal |
| 41 | + "c-extension-no-member", # not easy to implement in the current doc framework |
| 42 | + "config-parse-error", # configuration |
| 43 | + "fatal", # internal |
| 44 | + "import-self", # not easy to implement in the current doc framework |
| 45 | + "invalid-character-nul", # not easy to implement in the current doc framework |
| 46 | + "invalid-characters-in-docstring", # internal in py-enchant |
| 47 | + "invalid-unicode-codec", # placeholder (not implemented yet) |
| 48 | + "method-check-failed", # internal |
| 49 | + "parse-error", # internal |
| 50 | + "raw-checker-failed", # internal |
| 51 | + "unrecognized-option", # configuration |
| 52 | +} |
| 53 | +MESSAGES_WITHOUT_BAD_EXAMPLES = { |
| 54 | + "invalid-character-carriage-return", # can't be raised in normal pylint use |
| 55 | + "return-arg-in-generator", # can't be raised in modern python |
| 56 | +} |
| 57 | + |
37 | 58 |
|
38 | 59 | class MessageData(NamedTuple): |
39 | 60 | checker: str |
@@ -99,6 +120,11 @@ def _get_pylintrc_code(data_path: Path) -> str: |
99 | 120 |
|
100 | 121 | def _get_demo_code_for(data_path: Path, example_type: ExampleType) -> str: |
101 | 122 | """Get code examples while handling multi-file code templates.""" |
| 123 | + if data_path.name in MESSAGES_WITHOUT_EXAMPLES or ( |
| 124 | + data_path.name in MESSAGES_WITHOUT_BAD_EXAMPLES |
| 125 | + and example_type is ExampleType.BAD |
| 126 | + ): |
| 127 | + return "" |
102 | 128 | single_file_path = data_path / f"{example_type.value}.py" |
103 | 129 | multiple_code_path = data_path / f"{example_type.value}" |
104 | 130 |
|
@@ -130,8 +156,9 @@ def _get_demo_code_for(data_path: Path, example_type: ExampleType) -> str: |
130 | 156 | """ |
131 | 157 | ) |
132 | 158 | return _get_titled_rst(title=title, text="\n".join(files)) |
133 | | - |
134 | | - return "" |
| 159 | + raise AssertionError( |
| 160 | + f"Please add a {example_type.value} code example for {data_path}" |
| 161 | + ) |
135 | 162 |
|
136 | 163 |
|
137 | 164 | def _check_placeholders( |
@@ -187,9 +214,7 @@ def _get_ini_as_rst(code_path: Path) -> str: |
187 | 214 | """ |
188 | 215 |
|
189 | 216 |
|
190 | | -def _get_all_messages( |
191 | | - linter: PyLinter, |
192 | | -) -> tuple[MessagesDict, OldMessagesDict]: |
| 217 | +def _get_all_messages(linter: PyLinter) -> tuple[MessagesDict, OldMessagesDict]: |
193 | 218 | """Get all messages registered to a linter and return a dictionary indexed by |
194 | 219 | message type. |
195 | 220 |
|
@@ -241,8 +266,8 @@ def _get_all_messages( |
241 | 266 | if message.old_names: |
242 | 267 | for old_name in message.old_names: |
243 | 268 | category = MSG_TYPES_DOC[old_name[0][0]] |
244 | | - # We check if the message is already in old_messages so |
245 | | - # we don't duplicate shared messages. |
| 269 | + # We check if the message is already in old_messages, so we don't |
| 270 | + # duplicate shared messages. |
246 | 271 | if (message.symbol, msg_type) not in old_messages[category][ |
247 | 272 | (old_name[1], old_name[0]) |
248 | 273 | ]: |
@@ -328,7 +353,7 @@ def _generate_single_message_body(message: MessageData) -> str: |
328 | 353 |
|
329 | 354 | """ |
330 | 355 |
|
331 | | - body += "\n" + message.example_code + "\n" |
| 356 | + body += f"\n{message.example_code}\n" |
332 | 357 |
|
333 | 358 | if message.checker_module_name.startswith("pylint.extensions."): |
334 | 359 | body += f""" |
|
0 commit comments