-
Notifications
You must be signed in to change notification settings - Fork 96
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.
Looking good!
7d1e9b2
to
412d622
Compare
@macournoyer okay ready for review! |
Add tests and fixes Fix style
412d622
to
ac05bfb
Compare
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.
Awesome work! We can now replace the old theme-lint 🎉
offenses = analyze_theme( | ||
ThemeCheck::ValidHTMLTranslation.new, | ||
"locales/en.default.json" => JSON.dump( | ||
hello_html: "<h1>Hello, world</h1>" |
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.
Oh! One more thing. Can you test it will not cause errors w/ self-closing tags: <img src="...>
or <br>
.
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 updated to use Nokogumbo
, details in the PR description 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.
Nice find! Didn't know about nokogumbo. Looks perfect.
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 spent some time looking for a parser that would be easy to use and did not come across Nokogumbo, but looks great. Well done!
Left some minor comments but from my perspective this is a great addition.
|
||
def html_key?(keys) | ||
pluralized_key = keys[-2] if keys.length > 1 | ||
keys[-1].end_with?('_html') || pluralized_key.end_with?('_html') |
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.
The check for "is this a pluralization set of keys?" is a bit different than what we had in ThemeCheck::MatchingTranslations
but I think that's a good enough heuristic, and we can tweak those later if need be.
theme-check/lib/theme_check/checks/matching_translations.rb
Lines 84 to 88 in f1956ef
def pluralization?(hash) | |
hash.all? do |key, value| | |
PLURALIZATION_KEYS.include?(key) && !value.is_a?(Hash) | |
end | |
end |
'hello_html' contains invalid HTML: | ||
1:17: ERROR: Premature end of file Currently open tags: html, h1. | ||
<h1>Hello, world | ||
^ |
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.
The error messages are a bit odd when we're parsing single lines, wonder if we can tweak them? Here for instance
1:17:
Line 1 most likely isn't line 1
Premature end of file
From a consumer's perspective, a string is being parsed, not a file, right?
Currently open tags: html, h1.
Looks like html is automatically injected here.
Do you think there's a way for us to improve these?
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.
Agree with all the points above, but sadly most of these information are only available through the to_s
method. We are able to obtain the line and column values, and also str1
which returns the HTML standard error code. (source)
If we are printing only the error code, it will look like
suggestion: ValidHTMLTranslation: 'hello_html' contains invalid HTML: eof-in-tag, generic-parser.
Which is still okay, it doesn't point to the exact location of the error, but can be helpful
Merging this. We can tweak the error message in another PR. I've used dirty regexes in other places to do it :/ |
Fixes #59
I'm running into issues validating HTML with
Nokogiri
(img, br, svg tags are flagged as errors), I've switched it out toNokogumbo
after checking this issue. Getting good results with that so far.en.default.json
dev check path/to/my/theme