AntonNiklasson / eslint-plugin-knex

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

`this.knex` is not identified as knex client and cause parsing to fail #23

Open octo-topi opened 1 year ago

octo-topi commented 1 year ago

I set up knex client as specified in the doc

Lint fails on this file

I strip down the file to a maximum and still gets the following message

TypeError: Cannot read properties of undefined (reading 'name')
Occurred while linting /home/octo-topi/Documents/Octo/Missions/Pix/repositories/pix/api/db/database-builder/database-builder.js:9
Rule: "knex/avoid-injections

Here is the stripped version

class Test {
  constructor({ knex}) {
    this.knex = knex;
  }

  async query() {
    const query = 'select ? from users';
    const bindingParameters = ['email'];
    await this.knex.raw(query, bindingParameters);
  }
}

export { Test };

.eslintrc.cjs is below - With no settings, lint pass

  settings: {
    knex: {
      builderName: "^(knex)$"
    }
  }

Look like the callee structrure is quite different with this

image

So the node.callee.object.name does not exists

        if (context.settings && context.settings.knex) {
          const builder = node.callee.object;
          const builderName = builder.name || builder.callee.name;
AntonNiklasson commented 8 months ago

Hi, sorry for not getting back to you here. I'm not using this myself anymore so haven't spent any time on it.

So the solution would be to additionally look for the configured builder on a ThisExpression?