Netflix / x-element

A dead simple starting point for custom elements.
Apache License 2.0
29 stars 12 forks source link

Adopts shared linter rules #177

Closed klebba closed 7 months ago

klebba commented 7 months ago

One new violation:

~/x-element.js
  1328:53  warning  Function declared in a loop contains unsafe references to variable(s) 'node'  no-loop-func

✖ 1 problem (0 errors, 1 warning)
klebba commented 7 months ago

@theengineear how do you recommend I address the no-loop-func violation? I could ignore it or rework it (could use your help with that)

theengineear commented 7 months ago

Can you just change that find function from:

    const find = path => {
      let node = content;
      for (const index of path) {
        node = Template.#setIfMissing(lookup, node, () => node.childNodes)[index];
      }
      return node;
    };

to

    const find = path => {
      let node = content;
      for (const index of path) {
        const ref = node;
        node = Template.#setIfMissing(lookup, node, () => ref.childNodes)[index];
      }
      return node;
    };

The rule is just complaining about the fact that I’ve referenced something in a callback where the reference may change by the time it’s called back. It’s a fair warning 🤷

klebba commented 7 months ago

Thanks for the explainer! Fixt.