-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
rules: { | ||
'avoid-injections': require('./rules/avoid-injections') | ||
'avoid-injections': require('./rules/avoid-injections'), | ||
'avoid-updating-all-rows': require('./rules/avoid-updating-all-rows') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const meta = { | ||
type: "problem", | ||
docs: { | ||
description: "Avoid updating all rows", | ||
}, | ||
messages: { | ||
avoid: `Avoid updating all rows`, | ||
}, | ||
}; | ||
|
||
const create = function (context) { | ||
return { | ||
[`CallExpression[callee.property.name='update'][callee.object.callee.name='knex']`](node) { | ||
check(context, node); | ||
}, | ||
}; | ||
}; | ||
const check = function (context, node) { | ||
|
||
context.report({ | ||
node, | ||
messageId: "avoid" | ||
}); | ||
}; | ||
|
||
module.exports = { meta, create }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { RuleTester } = require("eslint"); | ||
const rule = require("./avoid-updating-all-rows"); | ||
|
||
function invalidCase(code, errors = [], others = {}) { | ||
return Object.assign( | ||
{ | ||
code, | ||
errors, | ||
}, | ||
others, | ||
); | ||
} | ||
|
||
const tester = new RuleTester({ | ||
parserOptions: { ecmaVersion: 2015 }, | ||
}); | ||
|
||
tester.run("avoid-updating-all-rows", rule, { | ||
valid: ["knex('books').where({id:1}).update({'status': 'archived'})"], | ||
invalid: [ | ||
invalidCase("knex('books').update({'status': 'archived'})", [ | ||
{ messageId: "avoid" }, | ||
]), | ||
], | ||
}); |