eslint-plugin-drizzle 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ const deleteRule = createRule({
|
|
|
14
14
|
},
|
|
15
15
|
fixable: 'code',
|
|
16
16
|
messages: {
|
|
17
|
-
enforceDeleteWithWhere:
|
|
17
|
+
enforceDeleteWithWhere: "Without `.where(...)` you will delete all the rows in a table. If you didn't want to do it, please use `db.delete(...).where(...)` instead. Otherwise you can ignore this rule here",
|
|
18
18
|
},
|
|
19
19
|
schema: [{
|
|
20
20
|
type: 'object',
|
|
@@ -30,7 +30,7 @@ const deleteRule = createRule({
|
|
|
30
30
|
return {
|
|
31
31
|
MemberExpression: (node) => {
|
|
32
32
|
if (node.property.type === 'Identifier') {
|
|
33
|
-
if (
|
|
33
|
+
if (node.property.name === 'delete' && lastNodeName !== 'where' && (0, options_1.isDrizzleObj)(node, options)) {
|
|
34
34
|
context.report({
|
|
35
35
|
node,
|
|
36
36
|
messageId: 'enforceDeleteWithWhere',
|
package/src/utils/options.js
CHANGED
|
@@ -3,17 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isDrizzleObj = void 0;
|
|
4
4
|
const isDrizzleObj = (node, options) => {
|
|
5
5
|
const drizzleObjectName = options[0].drizzleObjectName;
|
|
6
|
-
if (node.object.type === 'Identifier'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
if (Array.isArray(drizzleObjectName)) {
|
|
11
|
-
if (drizzleObjectName.length === 0) {
|
|
6
|
+
if (node.object.type === 'Identifier') {
|
|
7
|
+
if (typeof drizzleObjectName === 'string'
|
|
8
|
+
&& node.object.name === drizzleObjectName) {
|
|
12
9
|
return true;
|
|
13
10
|
}
|
|
14
|
-
if (
|
|
11
|
+
if (Array.isArray(drizzleObjectName)) {
|
|
12
|
+
if (drizzleObjectName.length === 0) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (drizzleObjectName.includes(node.object.name)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else if (node.object.type === 'MemberExpression' && node.object.property.type === 'Identifier') {
|
|
21
|
+
if (typeof drizzleObjectName === 'string'
|
|
22
|
+
&& node.object.property.name === drizzleObjectName) {
|
|
15
23
|
return true;
|
|
16
24
|
}
|
|
25
|
+
if (Array.isArray(drizzleObjectName)) {
|
|
26
|
+
if (drizzleObjectName.length === 0) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (drizzleObjectName.includes(node.object.property.name)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
17
33
|
}
|
|
18
34
|
return false;
|
|
19
35
|
};
|