Skip to content
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

Detect invalid nested helpers in theme #94

Open
cobbspur opened this issue Jan 2, 2018 · 4 comments
Open

Detect invalid nested helpers in theme #94

cobbspur opened this issue Jan 2, 2018 · 4 comments

Comments

@cobbspur
Copy link
Member

cobbspur commented Jan 2, 2018

Detect invalid nested helpers
Example:

{{#prev_post}}
    <div class="{{^next_post}}full-width{{/next_post}}" >
        ...
    </div>
{{/prev_post}}
@kevinansfield
Copy link
Member

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?

@naz
Copy link
Contributor

naz commented Apr 16, 2019

@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.

@kevinansfield
Copy link
Member

So I think there are a couple of things here...

  1. {{#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.
  2. {{#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:

  1. a rule that detects nested async helpers (are we sure nested async helpers will always fail?)
  2. 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 🤔

@naz
Copy link
Contributor

naz commented Apr 19, 2019

Think we can introduce both rules as they would be quite helpful.

  1. 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?

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants