Skip to content

Commit 1196a31

Browse files
committed
Show allowed languages when no or invalid language is supplied. Improve line lengths.
1 parent 7f0f517 commit 1196a31

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

tests/checkers/rst-yamllint.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
"error",
2424
}
2525

26+
ALLOWED_LANGUAGES = {
27+
"ansible-output",
28+
"bash",
29+
"console",
30+
"csharp",
31+
"diff",
32+
"ini",
33+
"jinja",
34+
"json",
35+
"md",
36+
"none",
37+
"powershell",
38+
"python",
39+
"rst",
40+
"sh",
41+
"shell",
42+
"shell-session",
43+
"text",
44+
}
45+
2646

2747
class IgnoreDirective(Directive):
2848
has_content = True
@@ -87,7 +107,12 @@ def visit_literal_block(self, node: nodes.literal_block) -> None:
87107
"path": self.__path,
88108
"line": node.line or "unknown",
89109
"col": 0,
90-
"message": f"Warning: found unknown literal block! Check for double colons '::'. If that is not the cause, please report this warning. It might indicate a bug in the checker or an unsupported Sphinx directive. Node: {node!r}; attributes: {node.attributes}; content: {node.rawsource!r}",
110+
"message": (
111+
"Warning: found unknown literal block! Check for double colons '::'."
112+
" If that is not the cause, please report this warning."
113+
" It might indicate a bug in the checker or an unsupported Sphinx directive."
114+
f" Node: {node!r}; attributes: {node.attributes}; content: {node.rawsource!r}"
115+
),
91116
}
92117
)
93118
raise nodes.SkipNode
@@ -133,40 +158,31 @@ def visit_literal_block(self, node: nodes.literal_block) -> None:
133158
# Now that we have the offsets, we can actually do some processing...
134159
if language not in {"YAML", "yaml", "yaml+jinja", "YAML+Jinja"}:
135160
if language is None:
161+
allowed_languages = ", ".join(sorted(ALLOWED_LANGUAGES))
136162
self.__results.append(
137163
{
138164
"path": self.__path,
139165
"line": row_offset + 1,
140166
"col": col_offset + 1,
141-
"message": "Literal block without language!",
167+
"message": (
168+
"Literal block without language!"
169+
f" Allowed languages are: {allowed_languages}."
170+
),
142171
}
143172
)
144173
return
145-
if language not in {
146-
"ansible-output",
147-
"bash",
148-
"console",
149-
"csharp",
150-
"diff",
151-
"ini",
152-
"jinja",
153-
"json",
154-
"md",
155-
"none",
156-
"powershell",
157-
"python",
158-
"rst",
159-
"sh",
160-
"shell",
161-
"shell-session",
162-
"text",
163-
}:
174+
if language not in ALLOWED_LANGUAGES:
175+
allowed_languages = ", ".join(sorted(ALLOWED_LANGUAGES))
164176
self.__results.append(
165177
{
166178
"path": self.__path,
167179
"line": row_offset + 1,
168180
"col": col_offset + 1,
169-
"message": f"Warning: literal block with disallowed language: {language}. If the language should be allowed, the checker needs to be updated.",
181+
"message": (
182+
f"Warning: literal block with disallowed language: {language}."
183+
" If the language should be allowed, the checker needs to be updated."
184+
f" Currently allowed languages are: {allowed_languages}."
185+
),
170186
}
171187
)
172188
raise nodes.SkipNode
@@ -199,7 +215,10 @@ def visit_literal_block(self, node: nodes.literal_block) -> None:
199215
"path": self.__path,
200216
"line": row_offset + 1,
201217
"col": col_offset + 1,
202-
"message": f"Internal error while linting YAML: exception {type(exc)}: {error}; traceback: {traceback.format_exc()!r}",
218+
"message": (
219+
f"Internal error while linting YAML: exception {type(exc)}:"
220+
f" {error}; traceback: {traceback.format_exc()!r}"
221+
),
203222
}
204223
)
205224

0 commit comments

Comments
 (0)