TypeError: Cannot read properties of undefined (reading 'name')
Occurred while linting /my-project/db/migrations/20210413124138_rename_enum_to_pascal_case.js:2
Rule: "knex/avoid-injections"
at CallExpression[callee.property.name=/^(raw|whereRaw|joinRaw)$/][arguments.0.type!='Literal'] (/my-project/node_modules/eslint-plugin-knex/rules/avoid-injections.js:24:62)
at ruleErrorHandler (/my-project/node_modules/eslint/lib/linter/linter.js:1076:28)
at /my-project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/my-project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/my-project/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/my-project/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/my-project/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/my-project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
at /my-project/node_modules/eslint/lib/linter/linter.js:1107:32
Hi, I'm trying to use the plugin to test DB migration files that use
knex.schema.raw(...)
. And the plugin fails and eslint doesn't execute further.Looked into the
avoid-injections.test.js
file and saw that the rule don't cover that case at all.Debugged a bit and found out it happens when I have
settings.knex.builderName = ...
set .eslintrc as that runs conditional code - https://github.com/AntonNiklasson/eslint-plugin-knex/blob/master/rules/avoid-injections.js#L19Error message:
Update
Added a PR https://github.com/AntonNiklasson/eslint-plugin-knex/pull/17 that adds the test cases for
knex.schema.raw
function to aid you in fixing the issue.