AntonNiklasson / eslint-plugin-knex

Lint rule(s) for Knex.js
9 stars 8 forks source link

Bug: Query string from another scope triggers error #1

Closed adrianhelvik closed 3 years ago

adrianhelvik commented 3 years ago

There is a bug when the string used for queries are located in another scope.

const END_TIME_QUERY = `now() + interval '123 seconds'`

export default async function updateEndTime() {
  await await db('foo').update({
    ends_at: knex.raw(END_TIME_QUERY),
  })
}

This triggers an error in eslint-plugin-knex/rules/avoid-injections.js:44:56

      .getScope(queryNode)
      .variables.find((v) => v.name === queryNode.name).defs[0].node;
                                                         // ^ Here
adrianhelvik commented 3 years ago

I think an error would be okay, as this requires extra attention. But this bug makes it impossible to suppress the error.

AntonNiklasson commented 3 years ago

Thanks for reporting this! I'll have a look.

AntonNiklasson commented 3 years ago

@adrianhelvik A patch for this is live in v0.1.2. Thanks again for the report 😊