-
-
Notifications
You must be signed in to change notification settings - Fork 183
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 HTML Linter #998
Merged
Merged
Add HTML Linter #998
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"alt-require": true, | ||
"attr-lowercase": ["viewBox"], | ||
"attr-value-double-quotes": true, | ||
"attr-value-not-empty": false, | ||
"attr-no-duplication": true, | ||
"attr-unsafe-chars": true, | ||
"doctype-first": false, | ||
"doctype-html5": true, | ||
"empyty-tag-self-close": true, | ||
"id-unique": false, | ||
"id-class-value": true, | ||
"head-script-disabled": false, | ||
"href-abs-or-rel": false, | ||
"id-class-ad-disabled": true, | ||
"inline-style-disabled": true, | ||
"inline-script-disabled": true, | ||
"space-tab-mixed-disabled": "space", | ||
"spec-char-escape": false, | ||
"src-not-empty": true, | ||
"style-disabled": false, | ||
"tag-pair": true, | ||
"tagname-lowercase": true, | ||
"title-require": true | ||
} |
This file contains 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.
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.
Do we not want to enforce ID uniqueness?
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.
Yes, ideally but can't due to reuse in some templates as per my PR description above.
For example the
previous-chapter
id here:almanac.httparchive.org/src/templates/base/2019/base_chapter.html
Lines 183 to 206 in fdbdbe9
Only one of these ends up in the template as it is surround in
{% if ... %}/{% else %}/{% endif %}
Jinja2 constructs but HTMLHint doesn't know that.And also loads of instances in ebook template which is generated.
Would be a bit of refactoring to prevent this, and not 100% sure we should to be honest. Could make the Jinja2 code more complex to write and read.
Ideally it would be nice if HTMLHint allowed us to ignore certain ids but it currently doesn't.
I say we go with what we have at present, as still loads of benefits to the other checks. We could then look to enforce it later, or look at linting the actual HTML produced in the end as discussed above.
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.
Yes, you are right, in conditional templates it is very possible and only a smart template linter can detect the branch in place. We can enforce this if and when we decide to lint the generated HTML later, so I will approve this PR.
Ideally, we would have added a comment next to this rule, explaining why we chose what we did, but unfortunately JSON does not support comments (unless we are using JSON5)
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.
I've seen some linters support a comment disabling certain rules for specific lines of code. Does this linter have a feature like that so we can enable the unique ID rule but turn it off in cases where the IDs are conditionally added?
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.
I’ve configured it where possible. Note I allow viewBox to be an exception to the rule that attributes must be all lowercase a few lines above.
However this rule doesn’t allow any configuration but on or off. Kind of makes sense to be honest. It’s not HTML but a temp laying language that is the reason we want to turn this off.
Still. I was pleasantly surprised how few rules I had to turn off so think there’s still a lot of value in this. We’ll look at linting output HTML as part of a nightly build as think we can run other stuff (e.g. Lighthouse, test that every page returns a 200... etc.). I’ve broken the sitemap on previous releases when changing python so think that would be a good test script to be able to run offline on demand (e.g. when doing a release) and nightly on
main
.