Registry / database / eslint-plugin-knex

eslint-plugin-knex

JSON →
library0.2.2jsnpmunverified

ESLint plugin that enforces safe SQL query practices when using Knex.js, particularly preventing SQL injection by disallowing plain string arguments in raw queries. The current stable version is 0.2.2, released with no recent active development (last update years ago). It offers a single rule, `avoid-injections`, and allows configuration of expected Knex builder variable names. Unlike generic SQL injection linting, this plugin is tailored specifically to Knex's `knex.raw()` method, filling a niche for projects heavily relying on raw queries.

npm install eslint-plugin-knex
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-KNEX
E
eslint-plugin-knex
databasejavascriptv0.2.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin
✓ { "plugins": ["knex"], "rules": { "knex/avoid-injections": "error" } }
✗ const plugin = require('eslint-plugin-knex')
ESLint plugins are not imported directly in code; they are referenced by name in the ESLint config.
avoid-injections rule
✓ "knex/avoid-injections": "error"
✗ "avoid-injections": "error"
Rule must be prefixed with the plugin namespace 'knex/'.

Configures ESLint to use the knex plugin and enforce the avoid-injections rule with custom builder name pattern.

// .eslintrc.js module.exports = { plugins: ['knex'], rules: { 'knex/avoid-injections': 'error' }, settings: { knex: { builderName: '^(knex|trx)$' } } };
Debug
Known issues
gotchaThe plugin only provides a single rule; other potential Knex linting needs (e.g., using .where with raw) are not covered.
fix
Supplement with additional ESLint rules or custom linting as needed.
affects: >=0.0.1
deprecatedPlugin has not been updated since 2018; may not support newer ESLint versions or Knex features.
fix
Consider alternatives or test compatibility with your ESLint/Knex versions.
affects: >=0.2.2
gotchaThe rule 'avoid-injections' flags any plain string argument to raw(), including legitimate cases (e.g., simple constant queries).
fix
Ensure all raw queries use template literals or parameterized syntax, or suppress the rule with inline comments where appropriate.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Failed to load plugin 'knex' declared in '.eslintrc': Cannot find module 'eslint-plugin-knex'
Plugin not installed as a devDependency.
fix
npm install -D eslint-plugin-knex
Rule 'knex/avoid-injections' was not found. Did you mean to use 'avoid-injections'?
Rule referenced without the plugin namespace prefix.
fix
Use 'knex/avoid-injections' instead of 'avoid-injections'.
Configuration for rule 'knex/avoid-injections' is invalid: Value should be string (error/warn/off).
Rule severity configured incorrectly, e.g., as a number or object.
fix
Set rule value to 'error', 'warn', or 'off'.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
eslintrequiredpeer dependency: requires ESLint to function as a plugin.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
eslint-plugin-knex — npm install eslint-plugin-knex · libregistry