Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lint rule for /> syntax on non-void HTML elements #40498

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,17 @@ SET TIMEOUT: editing/crashtests/outdent-across-svg-boundary.html
SET TIMEOUT: editing/crashtests/textarea-will-be-blurred-by-focus-event-listener.html
SET TIMEOUT: mathml/crashtests/mozilla/*
PARSE-FAILED: mathml/crashtests/mozilla/289180-1.xml

# Invalid HTML syntax /> on non-void elements
HTML INVALID SYNTAX: acid/*
HTML INVALID SYNTAX: conformance-checkers/*
HTML INVALID SYNTAX: css/css-scoping/shadow-cascade-order-001.html
HTML INVALID SYNTAX: dom/nodes/Document-createElement-namespace.html
HTML INVALID SYNTAX: dom/nodes/Node-lookupNamespaceURI.html
HTML INVALID SYNTAX: dom/nodes/Node-normalize.html
HTML INVALID SYNTAX: domparsing/DOMParser-parseFromString-xml-doctype.html
HTML INVALID SYNTAX: domparsing/DOMParser-parseFromString-xml-parsererror.html
HTML INVALID SYNTAX: domparsing/XMLSerializer-serializeToString.html
HTML INVALID SYNTAX: html/canvas/element/manual/unclosed-canvas-4.htm
HTML INVALID SYNTAX: quirks/percentage-height-calculation.html
HTML INVALID SYNTAX: trusted-types/TrustedTypePolicyFactory-getAttributeType-namespace.tentative.html
3 changes: 2 additions & 1 deletion tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ def filter_ignorelist_errors(data: Ignorelist, errors: Sequence[rules.Error]) ->
rules.SpecialPowersRegexp,
rules.AssertThrowsRegexp,
rules.PromiseRejectsRegexp,
rules.AssertPreconditionRegexp]]
rules.AssertPreconditionRegexp,
rules.HTMLInvalidSyntaxRegexp]]


def check_regexp_line(repo_root: Text, path: Text, f: IO[bytes]) -> List[rules.Error]:
Expand Down
12 changes: 12 additions & 0 deletions tools/lint/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,15 @@ class AssertPreconditionRegexp(Regexp):
file_extensions = [".html", ".htm", ".js", ".xht", ".xhtml", ".svg"]
description = "Test-file line has an `assert_precondition(...)` call"
to_fix = """Replace with `assert_implements` or `assert_implements_optional`"""


class HTMLInvalidSyntaxRegexp(Regexp):
pattern = (br"<(a|abbr|article|audio|b|bdi|bdo|blockquote|body|button|canvas|caption|cite|code|colgroup|data|datalist|dd|del|details|"
br"dfn|dialog|div|dl|dt|em|fieldset|figcaption|figure|footer|form|h[1-6]|head|header|html|i|iframe|ins|kbd|label|legend|li|"
br"main|map|mark|menu|meter|nav|noscript|object|ol|optgroup|option|output|p|picture|pre|progress|q|rp|rt|ruby|s|samp|script|"
br"search|section|select|slot|small|span|strong|style|sub|summary|sup|table|tbody|td|template|textarea|tfoot|th|thead|time|"
br"title|tr|u|ul|var|video)(\s+[^>]+)?\s*/>")
name = "HTML INVALID SYNTAX"
file_extensions = [".html", ".htm"]
description = "Test-file line has a non-void HTML tag with /> syntax"
to_fix = """Replace with start tag and end tag"""
10 changes: 10 additions & 0 deletions tools/lint/tests/test_file_lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ def test_no_missing_deps():
assert errors == []


def test_html_invalid_syntax():
error_map = check_with_files(b"<!doctype html><div/>")

for (filename, (errors, kind)) in error_map.items():
check_errors(errors)

if kind == "web-lax":
assert errors == [("HTML INVALID SYNTAX", "Test-file line has a non-void HTML tag with /> syntax", filename, 1)]


def test_meta_timeout():
code = b"""
<html xmlns="http://www.w3.org/1999/xhtml">
Expand Down
Loading