- Notifications
You must be signed in to change notification settings - Fork302
Lint fixes#222
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Lint fixes#222
Changes fromall commits
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
40c3ba6 Fix lint to expect text_type everywhere
gsneddersfbbea1f Update lint filter for namespaced attributes
gsnedders8b4d7c4 Drop the content model requirements from lint
gsnedders270a2ca Don't let the lxml treewalker walk above the fragment root
gsnedders66ef026 Teach lint & treewalkers that elements are only void in HTML ns
gsnedders5bd3413 Use lint filter to ensure validity of treewalkers
gsneddersfb9e177 Remove runtime type checks from treewalkers._base
gsnedders2a5d7af Make sure we have the unicode from of text in lxml fragment root
gsnedders9eff304 Allow None as a doctype tagname in lint
gsnedderse0ea899 Drop all the to_text magic in treewalkers._base
gsnedders22c2b1a Get rid of LintError and just use asserts
gsnedders5336ebe Lint that comments are text_type
gsneddersdc879ff Don't allow ParseError/SerializerError tokens, whatever they are!
gsnedders7f8bd13 Drop end tag tree walker's data (always empty now)
gsneddersc335295 Drop tree walker doctype correct flag, whatever that once was!
gsneddersca6591c Make sure lint is testing everything treewalkers can do.
gsneddersFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
101 changes: 44 additions & 57 deletionshtml5lib/filters/lint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,90 +1,77 @@ | ||
| from __future__ import absolute_import, division, unicode_literals | ||
| from six import text_type | ||
| from . import _base | ||
| from ..constants importnamespaces, voidElements | ||
| from ..constants import spaceCharacters | ||
| spaceCharacters = "".join(spaceCharacters) | ||
| class Filter(_base.Filter): | ||
| def __iter__(self): | ||
| open_elements = [] | ||
| for token in _base.Filter.__iter__(self): | ||
| type = token["type"] | ||
| if type in ("StartTag", "EmptyTag"): | ||
| namespace = token["namespace"] | ||
| name = token["name"] | ||
| assert namespace is None or isinstance(namespace, text_type) | ||
| assert namespace != "" | ||
| assert isinstance(name, text_type) | ||
| assert name != "" | ||
| assert isinstance(token["data"], dict) | ||
| if (not namespace or namespace == namespaces["html"]) and name in voidElements: | ||
| assert type == "EmptyTag" | ||
| else: | ||
| assert type == "StartTag" | ||
| if type == "StartTag": | ||
| open_elements.append((namespace, name)) | ||
| for (namespace, name), value in token["data"].items(): | ||
| assert namespace is None or isinstance(namespace, text_type) | ||
| assert namespace != "" | ||
| assert isinstance(name, text_type) | ||
| assert name != "" | ||
| assert isinstance(value, text_type) | ||
| elif type == "EndTag": | ||
| namespace = token["namespace"] | ||
| name = token["name"] | ||
| assert namespace is None or isinstance(namespace, text_type) | ||
| assert namespace != "" | ||
| assert isinstance(name, text_type) | ||
| assert name != "" | ||
| if (not namespace or namespace == namespaces["html"]) and name in voidElements: | ||
| assert False, "Void element reported as EndTag token: %(tag)s" % {"tag": name} | ||
| else: | ||
| start = open_elements.pop() | ||
| assert start == (namespace, name) | ||
| elif type == "Comment": | ||
| data = token["data"] | ||
| assert isinstance(data, text_type) | ||
| elif type in ("Characters", "SpaceCharacters"): | ||
| data = token["data"] | ||
| assert isinstance(data, text_type) | ||
| assert data != "" | ||
| if type == "SpaceCharacters": | ||
| assert data.strip(spaceCharacters) == "" | ||
| elif type == "Doctype": | ||
| name = token["name"] | ||
| assert name is None or isinstance(name, text_type) | ||
| assert token["publicId"] is None or isinstance(name, text_type) | ||
| assert token["systemId"] is None or isinstance(name, text_type) | ||
| elif type == "Entity": | ||
| assert isinstance(token["name"], text_type) | ||
| elif type== "SerializerError": | ||
| assert isinstance(token["data"], text_type) | ||
| else: | ||
| assert False,"Unknown token type: %(type)s" % {"type": type} | ||
| yield token |
13 changes: 7 additions & 6 deletionshtml5lib/tests/test_treewalkers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
84 changes: 17 additions & 67 deletionshtml5lib/treewalkers/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionhtml5lib/treewalkers/genshistream.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletionhtml5lib/treewalkers/lxmletree.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.