|
23 | 23 | "error",
|
24 | 24 | }
|
25 | 25 |
|
| 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 | + |
26 | 46 |
|
27 | 47 | class IgnoreDirective(Directive):
|
28 | 48 | has_content = True
|
@@ -87,7 +107,12 @@ def visit_literal_block(self, node: nodes.literal_block) -> None:
|
87 | 107 | "path": self.__path,
|
88 | 108 | "line": node.line or "unknown",
|
89 | 109 | "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 | + ), |
91 | 116 | }
|
92 | 117 | )
|
93 | 118 | raise nodes.SkipNode
|
@@ -133,40 +158,31 @@ def visit_literal_block(self, node: nodes.literal_block) -> None:
|
133 | 158 | # Now that we have the offsets, we can actually do some processing...
|
134 | 159 | if language not in {"YAML", "yaml", "yaml+jinja", "YAML+Jinja"}:
|
135 | 160 | if language is None:
|
| 161 | + allowed_languages = ", ".join(sorted(ALLOWED_LANGUAGES)) |
136 | 162 | self.__results.append(
|
137 | 163 | {
|
138 | 164 | "path": self.__path,
|
139 | 165 | "line": row_offset + 1,
|
140 | 166 | "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 | + ), |
142 | 171 | }
|
143 | 172 | )
|
144 | 173 | 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)) |
164 | 176 | self.__results.append(
|
165 | 177 | {
|
166 | 178 | "path": self.__path,
|
167 | 179 | "line": row_offset + 1,
|
168 | 180 | "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 | + ), |
170 | 186 | }
|
171 | 187 | )
|
172 | 188 | raise nodes.SkipNode
|
@@ -199,7 +215,10 @@ def visit_literal_block(self, node: nodes.literal_block) -> None:
|
199 | 215 | "path": self.__path,
|
200 | 216 | "line": row_offset + 1,
|
201 | 217 | "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 | + ), |
203 | 222 | }
|
204 | 223 | )
|
205 | 224 |
|
|
0 commit comments