From 1207259ded5f9660451879f11672b441be1f0803 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Tue, 9 Jul 2024 13:24:13 -0500 Subject: [PATCH] lint: Add x-021,
with no @id attribute --- se/se_epub_lint.py | 6 ++++++ tests/lint/typos/y-003/golden/y-003-out.txt | 7 +++++++ tests/lint/xhtml/x-021/golden/x-021-out.txt | 0 tests/lint/xhtml/x-021/in/chapter-1.xhtml | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 tests/lint/xhtml/x-021/golden/x-021-out.txt create mode 100644 tests/lint/xhtml/x-021/in/chapter-1.xhtml diff --git a/se/se_epub_lint.py b/se/se_epub_lint.py index ce999f23..658fe2a7 100644 --- a/se/se_epub_lint.py +++ b/se/se_epub_lint.py @@ -452,6 +452,7 @@ "x-018", "Unused [xhtml]id[/] attribute." "x-019", "Unexpected value of [attr]id[/] attribute. Expected: [attr]{unexpected_id[1]}[/]." "x-020", "Link to [path][link=file://{local_css_path}]se.css[/][/] in [xhtml][/], but not an SE boilerplate file." +"x-021", "[xhtml]
[/] element with no [attr]id[/] attribute." TYPOS "y-001", "Possible typo: doubled [text]a/the/and/of/or/as/if[/]." @@ -2854,6 +2855,11 @@ def _lint_xhtml_xhtml_checks(filename: Path, dom: se.easy_xml.EasyXmlTree, file_ if nodes: messages.append(LintMessage("x-020", f"Link to [path][link=file://{local_css_path}]se.css[/][/] in [xhtml][/], but not an SE boilerplate file.", se.MESSAGE_TYPE_ERROR, filename, [node.to_tag_string() for node in nodes])) + # Check that all `` elements have an `@id` attribute. If the `` has a parent `
`, then the `
` should have the `@id`. + nodes = dom.xpath("/html/body//figure[not(@id)]") + if nodes: + messages.append(LintMessage("x-021", "[xhtml]
[/] element with no [attr]id[/] attribute.", se.MESSAGE_TYPE_ERROR, filename, [node.to_string() for node in nodes])) + return messages def _lint_xhtml_typo_checks(filename: Path, dom: se.easy_xml.EasyXmlTree, file_contents: str, special_file: Optional[str]) -> list: diff --git a/tests/lint/typos/y-003/golden/y-003-out.txt b/tests/lint/typos/y-003/golden/y-003-out.txt index a1dedcb5..9f993513 100644 --- a/tests/lint/typos/y-003/golden/y-003-out.txt +++ b/tests/lint/typos/y-003/golden/y-003-out.txt @@ -1,3 +1,10 @@ +x-021 [Error] chapter-1.xhtml `
` element with no `id` attribute. +
+
+ +

Look ma, no picture

+
+
y-003 [Manual Review] chapter-1.xhtml Possible typo: paragraph missing ending punctuation.

This one should error

diff --git a/tests/lint/xhtml/x-021/golden/x-021-out.txt b/tests/lint/xhtml/x-021/golden/x-021-out.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/lint/xhtml/x-021/in/chapter-1.xhtml b/tests/lint/xhtml/x-021/in/chapter-1.xhtml new file mode 100644 index 00000000..1dcbfb89 --- /dev/null +++ b/tests/lint/xhtml/x-021/in/chapter-1.xhtml @@ -0,0 +1,20 @@ + + + + I + + + + +
+ +
+ A portrait illustration of a young woman. +
+ +
+ A portrait illustration of a young woman. +
+
+ +