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

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

Open
octo-topi opened this issue Sep 22, 2023 · 1 comment
Open

Comments

@octo-topi
Copy link

octo-topi commented Sep 22, 2023

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;
@octo-topi octo-topi changed the title Identifier in raw parameter binding is not detected this.knex is not identified as knex client and cause parsing to fail Sep 22, 2023
@AntonNiklasson
Copy link
Owner

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?

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

No branches or pull requests

2 participants