-
Notifications
You must be signed in to change notification settings - Fork 62
Forbid comments with more than two dashes #87
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @TangSteven! Just one question :).
Additionally, would you mind adding a new spec for this to ensure that this behavior doesn't regress? Thanks again 🙇
grammars/xml.cson
Outdated
@@ -403,3 +403,9 @@ | |||
'name': 'punctuation.definition.comment.xml' | |||
'end': '--%?>' | |||
'name': 'comment.block.xml' | |||
'patterns': [ | |||
{ | |||
'match': '-{3,}>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is {3,}
and not {3}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if 3 dashes is invalid grammar, anything longer than 2 should also be invalid.
So if the end arrow was four long (---->)
{3} would only highlight - --->
{3,} highlights the entire arrow which makes more sense, ---->
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I feel like we should only be highlighting the last three.
@Ingramz any opinions on this?
I'm not quite sure how to add a new spec, would you mind pointing me in the right direction? |
Yeah, of course! Specs are added to https://github.com/atom/language-xml/blob/master/spec/xml-spec.coffee. It looks like there aren't a lot of specs yet for this language, but you can take a look at language-html's for inspiration. |
The specification mentions that the grammar for comments is following:
Simplified:
Which can be interpreted as This pull request in its current state only covers the example provided in specification, but not the general case, which leaves cases such as the following valid: <!-- Hello -- World --> Do note that the following is still valid: <!--- Hello World --> I think it would be easier to just make a rule within the body of comment that just searched for Edit: Also the comments for JSP ( |
Just create two separate rules like this: 'comments':
'patterns': [
{
'begin': '<%--'
'captures':
'0':
'name': 'punctuation.definition.comment.xml'
'end': '--%>'
'name': 'comment.block.xml'
}
{
'begin': '<!--'
'captures':
'0':
'name': 'punctuation.definition.comment.xml'
'end': '-->'
'name': 'comment.block.xml'
}
] Then work only on the second one. The lookbehind should be unnecessary. From the point where the error is first registered, the rest of the document will be invalid. To make it a little clearer where the error comes from, we can highlight the first occurrence only by making use of begin/end rule: 'patterns': [
{
'begin': '--(?!>)'
'beginCaptures':
'0':
'name': 'invalid.illegal.bad-comments-or-CDATA.xml'
}
] |
Also, only highlight first occurrence of `--`
Updated! |
atom#96 already provides all the details about the issues fixed here. atom#87 (comment) has the correct code but merge included some extra indent which causes the rule not to work properly. In relation with atom#91, a `begin` without `end` or `while` was added but this is not valid as `begin` should always have a corresponding `end` or `while`. `match` should be used instead of `begin`
Description of the Change
Any comment ending with more than 2 dashes is now considered as
invalid.illegal.bad-comments-or-CDATA.xml
Alternate Designs
Benefits
Grammar no longer accepts
--->
comment ending that is forbidden by XML grammar.Possible Drawbacks
Applicable Issues
#84