gscan
gscan copied to clipboard
Detect invalid nested helpers in theme
Detect invalid nested helpers Example:
{{#prev_post}}
<div class="{{^next_post}}full-width{{/next_post}}" >
...
</div>
{{/prev_post}}
If I'm understanding it correctly, this is a fairly general problem of accessing properties which don't exist inside the current context.
{{#someObject}}
{{someProperty}} <!-- someObject.someProperty doesn't exist -->
{{/someObject}}
I wasn't able to produce any errors using the example in the issue. @gargol are you reading this the same way?
@kevinansfield my understanding is it's more about detecting usage of nested tags. In this situation it would be de detection of the following situation:
{{#next_post}}
{{^prev_post}}
<p>no prev post</p>
{{/prev_post}}
<p>has next post</p>
{{/next_post}}
{{^prev_post}}
<p>no prev post</p>
{{/prev_post}}
Where {{^prev_post}} works but only when it's not nested.
So I think there are a couple of things here...
{{#prev_post}}{{^next_post}}oops{{/next_post}}{{/prev_post}}will never render "oops" because the logic is incorrect. If "prev_post" is available for the outer context then "next_post" will always be available on the inner context meaning the{{^next_post}}inverse is not reachable.{{#next/prev_post}}are async helpers. Nested async helpers in the version of express-hbs we use are not strictly supported
Unfortunately the original issue is missing the context around what wasn't working or if any errors were encountered.
As far as the rule for this is concerned, I'm not sure where to go. There are two options:
- a rule that detects nested async helpers (are we sure nested async helpers will always fail?)
- a rule that detects usage of
{{#next/prev_post}}in a non-post context
Detecting the logic error in the issue's original template would be a lot more difficult I think 🤔
Think we can introduce both rules as they would be quite helpful.
- a rule that detects nested async helpers (are we sure nested async helpers will always fail?)
I think we could issue a warning for all of our async helpers when nested, similarly to what we already say in the docs already.
My suspicion now is that this is exactly the problem the issue was about. Maybe @cobbspur you magically remember about the contexts of this issue?
- a rule that detects usage of {{#next/prev_post}} in a non-post context
This one just makes sense, as it would be invalid to use in any other context.