From 7528651bdda5d7f7a969d58cb02ea6ec0696d66c Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Fri, 12 Mar 2021 21:42:51 +0000 Subject: [PATCH] Add more descriptive error message for missing whitespace between HTML attributes https://github.com/thibaudcolas/curlylint/issues/23#issuecomment-700622837 --- CHANGELOG.md | 4 ++++ curlylint/parse.py | 3 ++- curlylint/parse_test.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db882e3..92b620a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## Unreleased +### Changed + +- Add more descriptive error message for missing whitespace between HTML attributes ([#23 (comment)](https://github.com/thibaudcolas/curlylint/issues/23#issuecomment-700622837)) + ## [v0.12.2](https://github.com/thibaudcolas/curlylint/releases/tag/v0.12.2) 2021-03-06 ### Fixed diff --git a/curlylint/parse.py b/curlylint/parse.py index f66a8fa..612983b 100644 --- a/curlylint/parse.py +++ b/curlylint/parse.py @@ -150,6 +150,7 @@ # XXX: It could be better and simpler to only allow ASCII whitespaces here. whitespace = P.regex(r"\s*") mandatory_whitespace = P.regex(r"\s+") +spaces_between_attr = mandatory_whitespace.desc("space(s) between attributes") def until(parser): @@ -415,7 +416,7 @@ def make_attributes_parser(config, jinja): attrs = interpolated( ( - whitespace.then(jinja_attr) | mandatory_whitespace.then(attribute) + whitespace.then(jinja_attr) | spaces_between_attr.then(attribute) ).many() ) diff --git a/curlylint/parse_test.py b/curlylint/parse_test.py index f012d4f..48c3cc8 100644 --- a/curlylint/parse_test.py +++ b/curlylint/parse_test.py @@ -1,4 +1,5 @@ import unittest +import pytest import parsy as P @@ -221,6 +222,17 @@ def test_opening_tag(self): ), ) + def test_opening_tag_attributes_no_space(self): + # See https://html.spec.whatwg.org/multipage/syntax.html#start-tags + # "Attributes must be separated from each other by one or more ASCII whitespace." + # See https://github.com/thibaudcolas/curlylint/issues/23#issuecomment-700622837 + with pytest.raises( + P.ParseError, match="space\\(s\\) between attributes", + ): + opening_tag.parse( + 'Set cookie preferences' + ) + def test_closing_tag(): closing_tag = make_closing_tag_parser(P.string("div"))