ember-template-lint / eslint-plugin-hbs

Plugin for eslint which checks inline hbs templates
ISC License
18 stars 8 forks source link

TypeError: Cannot read property 'message' of undefined #42

Open EvgenyOrekhov opened 3 years ago

EvgenyOrekhov commented 3 years ago

I think this error appeared when I upgraded ember-template-lint to v3.

jakebixbyavalara commented 3 years ago

@jaydgruber also ran into this recently with the upgrade. He is locked out of his github account for the moment, so he asked me to post here, but it appears the issue is due to the TaggedTemplateExpression not using an async function.

// https://github.com/ember-template-lint/eslint-plugin-hbs/blob/master/lib/rules/check-hbs-template-literals.js#L73
      TaggedTemplateExpression: (node) => { // I think this needs to be an async function
        if (node.tag.name === 'hbs') {
          if (node.quasi.type === 'TemplateLiteral') {
            let hbs = node.quasi.quasis[0].value.cooked
            hbs = unindentAndStripSafeNewlines(hbs)
            const results = linter.verify({source: hbs.toString(), moduleId: context.id}) // and I think this needs to await
            if (results.length !== 0) {
              // If I log from here, `results = Promise { <pending> }`
              // so even though it has a length, `results[0] = undefined`
              const firstLine = results[0].message.split('\n')[0]
              const msg = `${results.length} error(s): ${firstLine}`
              context.report(node, msg)
            }
          }
        }
      },
rwjblue commented 3 years ago

Yeah, the issue is that I don't think ESLint allows async here 🤔

lifeart commented 3 years ago

@rwjblue wondering, should we add verifySync with filtering on async rules?

rwjblue commented 3 years ago

Ya probably :(

dfreeman commented 3 years ago

This seems to have broken template lint integration with non-unstable ELS (embertooling.vscode-ember):

(node:77599) UnhandledPromiseRejectionWarning: TypeError: errors.map is not a function
    at TemplateLinter.<anonymous> (/Users/dfreeman/.vscode/extensions/embertooling.vscode-ember-0.2.1/node_modules/@emberwatch/ember-language-server/lib/template-linter.js:38:38)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/dfreeman/.vscode/extensions/embertooling.vscode-ember-0.2.1/node_modules/@emberwatch/ember-language-server/lib/template-linter.js:4:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Sticking a console.log in there, I can see errors is a pending promise rather than an array.

(I realize that's not directly related to eslint-plugin-hbs, but this seems to be where the relevant conversation has landed)

lifeart commented 3 years ago

@dfreeman embertooling.vscode-ember is not really supported, consider Unstable LS as Stable

amk221 commented 2 years ago

What's the situation with this? I've had 'hbs/check-hbs-template-literals': 'off' for a while now and eager to get it back on