Skip to content

Commit 31cb4bf

Browse files
authored
DOP-1242: Warn about deprecated directives (#180)
1 parent eea68ae commit 31cb4bf

File tree

9 files changed

+38
-22
lines changed

9 files changed

+38
-22
lines changed

snooty/rstparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ def run(self) -> List[docutils.nodes.Node]:
408408
node["options"] = self.options
409409
self.add_name(node)
410410

411+
# If directive is deprecated, warn
412+
if self.directive_spec.deprecated == True:
413+
node.append(
414+
self.state.document.reporter.warning(
415+
f'Directive "{self.name}" has been deprecated', line=line
416+
)
417+
)
418+
411419
# If this is an rstobject, we need to generate a target property
412420
if rstobject_spec is not None:
413421
prefix = rstobject_spec.prefix + "." if rstobject_spec.prefix else ""

snooty/rstspec.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ charts_theme = ["light", "dark"]
1313

1414
[directive.default-domain]
1515
argument_type = "string"
16-
deprecated = true
1716

1817
[directive.div]
1918
deprecated = true

snooty/test_parser.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,28 @@ def test_problematic() -> None:
15431543
check_ast_testing_string(page.ast, "<root><paragraph></paragraph></root>")
15441544

15451545

1546+
def test_deprecated() -> None:
1547+
path = ROOT_PATH.joinpath(Path("test.rst"))
1548+
project_config = ProjectConfig(ROOT_PATH, "", source="./")
1549+
parser = rstparser.Parser(project_config, JSONVisitor)
1550+
1551+
page, diagnostics = parse_rst(
1552+
parser,
1553+
path,
1554+
"""
1555+
.. raw:: html
1556+
1557+
<div>Test raw directive</div>
1558+
""",
1559+
)
1560+
page.finish(diagnostics)
1561+
assert len(diagnostics) == 1
1562+
check_ast_testing_string(
1563+
page.ast,
1564+
"""<root><directive name="raw"><directive_argument><text>html</text></directive_argument><FixedTextElement /></directive></root>""",
1565+
)
1566+
1567+
15461568
def test_definition_list() -> None:
15471569
path = ROOT_PATH.joinpath(Path("test.rst"))
15481570
project_config = ProjectConfig(ROOT_PATH, "", source="./")

snooty/test_postprocess.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ def test_expand_includes(backend: Backend) -> None:
6868
<heading id="skip-includes">
6969
<text>Skip includes</text>
7070
</heading>
71-
<directive name="default-domain">
72-
<text>mongodb</text>
73-
</directive>
7471
<directive name="meta" keywords="connect">
7572
</directive>
7673
</section>
@@ -156,7 +153,7 @@ def test_role_explicit_title(backend: Backend) -> None:
156153
assert isinstance(ast, n.Root)
157154

158155
# Assert that ref_roles with an explicit title work
159-
paragraph = cast(Any, ast).children[1].children[4].children[1].children[2]
156+
paragraph = cast(Any, ast).children[1].children[3].children[1].children[2]
160157
assert isinstance(paragraph, n.Paragraph)
161158
ref_role = paragraph.children[1]
162159
print(ast_to_testing_string(ref_role))
@@ -243,7 +240,7 @@ def test_target_titles(backend: Backend) -> None:
243240
# Assert that titles are correctly located
244241
section = ast.children[1]
245242
assert isinstance(section, n.Parent)
246-
section = section.children[4]
243+
section = section.children[3]
247244
assert isinstance(section, n.Parent)
248245
target1 = section.children[-2]
249246
target2 = section.children[-1]
@@ -263,12 +260,12 @@ def test_program_option(backend: Backend) -> None:
263260
assert isinstance(ast, n.Root)
264261

265262
section: Any = ast.children[0]
266-
include = section.children[3]
267-
program1 = section.children[2]
263+
include = section.children[2]
264+
program1 = section.children[1]
268265
option1_1 = include.children[0]
269-
option1_2 = section.children[4]
270-
program2 = section.children[5]
271-
option2_1 = section.children[6]
266+
option1_2 = section.children[3]
267+
program2 = section.children[4]
268+
option2_1 = section.children[5]
272269

273270
# Test directives
274271
check_ast_testing_string(
@@ -332,7 +329,7 @@ def test_program_option(backend: Backend) -> None:
332329
assert len(diagnostics) == 1, diagnostics
333330
assert isinstance(diagnostics[0], AmbiguousTarget)
334331

335-
roles = section.children[7].children
332+
roles = section.children[6].children
336333
check_ast_testing_string(
337334
roles[0].children[0].children[0],
338335
"""

test_data/test_postprocessor/source/a-program.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
A Program
33
=========
44

5-
.. default-domain:: mongodb
6-
75
.. program:: a-program
86

97
.. include:: /includes/option-version.rst

test_data/test_postprocessor/source/includes/test.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@
55
Skip includes
66
=============
77

8-
.. default-domain:: mongodb
9-
108
.. meta::
119
:keywords: connect

test_data/test_postprocessor/source/index.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Connection Limits and Cluster Tier
55
====================================
66

7-
.. default-domain:: mongodb
8-
97
.. meta::
108
:keywords: connect
119

test_data/test_postprocessor/source/page1.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Print this heading
55
==================
66

7-
.. default-domain:: mongodb
8-
97
.. meta::
108
:keywords: connect
119

test_data/test_postprocessor/source/page2.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
Heading is not at the top for some reason
2020
=========================================
2121

22-
.. default-domain:: mongodb
23-
2422
.. meta::
2523
:keywords: connect
2624

0 commit comments

Comments
 (0)