eslint-plugin-nima 0.1.0 → 0.1.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.
|
@@ -5,33 +5,52 @@ const utils_1 = require("@typescript-eslint/utils");
|
|
|
5
5
|
exports.name = "manage-functions";
|
|
6
6
|
exports.rule = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
7
7
|
create(context, options) {
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const files = options[0].options[0].files;
|
|
11
|
-
const folders = options[0].options[0].folders;
|
|
12
|
-
if (!filename.includes("/routes/")) {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
8
|
+
var _a;
|
|
9
|
+
const allOptions = ((_a = options[0]) === null || _a === void 0 ? void 0 : _a.options) || [];
|
|
15
10
|
function isFileMatched(filename) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
return allOptions.some((option) => {
|
|
12
|
+
const folders = option.folders || [];
|
|
13
|
+
const files = option.files || [];
|
|
14
|
+
if (folders.some((f) => filename.includes(f)))
|
|
15
|
+
return true;
|
|
16
|
+
if (files.some((f) => filename.endsWith(f)))
|
|
17
|
+
return true;
|
|
18
|
+
return false;
|
|
19
|
+
});
|
|
21
20
|
}
|
|
22
21
|
function isFunctionDisabled(name) {
|
|
23
|
-
return
|
|
22
|
+
return allOptions.some((option) => {
|
|
23
|
+
const disableFunctions = option.disableFunctions || [];
|
|
24
|
+
return disableFunctions.some((fnName) => fnName.toLowerCase() === name);
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
27
|
return {
|
|
26
28
|
CallExpression(node) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const callee = node.callee;
|
|
30
|
+
if (!isFileMatched(context.filename))
|
|
31
|
+
return;
|
|
32
|
+
if (callee.type === "Identifier") {
|
|
33
|
+
if (isFunctionDisabled(callee.name.toLowerCase())) {
|
|
34
|
+
context.report({
|
|
35
|
+
data: {
|
|
36
|
+
fnName: callee.name,
|
|
37
|
+
},
|
|
38
|
+
messageId: "noOptional",
|
|
39
|
+
node: callee,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (callee.type === "MemberExpression" &&
|
|
44
|
+
callee.property.type === "Identifier") {
|
|
45
|
+
if (isFunctionDisabled(callee.property.name.toLowerCase())) {
|
|
46
|
+
context.report({
|
|
47
|
+
data: {
|
|
48
|
+
fnName: callee.property.name,
|
|
49
|
+
},
|
|
50
|
+
messageId: "noOptional",
|
|
51
|
+
node: callee.property,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
35
54
|
}
|
|
36
55
|
},
|
|
37
56
|
};
|
|
@@ -49,10 +68,10 @@ exports.rule = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
49
68
|
],
|
|
50
69
|
meta: {
|
|
51
70
|
docs: {
|
|
52
|
-
description: "Disallow use of
|
|
71
|
+
description: "Disallow use of any functions in any files or folders.",
|
|
53
72
|
},
|
|
54
73
|
messages: {
|
|
55
|
-
noOptional: "Do not use
|
|
74
|
+
noOptional: "Do not use {{ fnName }} in this folder/file.",
|
|
56
75
|
},
|
|
57
76
|
schema: [
|
|
58
77
|
{
|
|
@@ -85,13 +104,4 @@ exports.rule = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
85
104
|
type: "problem",
|
|
86
105
|
},
|
|
87
106
|
});
|
|
88
|
-
// "nima/manage-functions": ["error", {
|
|
89
|
-
// options: [
|
|
90
|
-
// {
|
|
91
|
-
// disableFunctions: ["..."],
|
|
92
|
-
// files: ["..."],
|
|
93
|
-
// folders: ["..."]
|
|
94
|
-
// }
|
|
95
|
-
// ]
|
|
96
|
-
// }]
|
|
97
107
|
//# sourceMappingURL=manage-functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manage-functions.js","sourceRoot":"","sources":["../../src/rules/manage-functions.ts"],"names":[],"mappings":";;;AAAA,oDAAiE;AAEpD,QAAA,IAAI,GAAG,kBAAkB,CAAC;AAE1B,QAAA,IAAI,GAAG,mBAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IACtD,MAAM,CAAC,OAAO,EAAE,OAAO
|
|
1
|
+
{"version":3,"file":"manage-functions.js","sourceRoot":"","sources":["../../src/rules/manage-functions.ts"],"names":[],"mappings":";;;AAAA,oDAAiE;AAEpD,QAAA,IAAI,GAAG,kBAAkB,CAAC;AAE1B,QAAA,IAAI,GAAG,mBAAW,CAAC,WAAW,CAAC,WAAW,CAAC;IACtD,MAAM,CAAC,OAAO,EAAE,OAAO;;QACrB,MAAM,UAAU,GAAG,CAAA,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,OAAO,KAAI,EAAE,CAAC;QAE7C,SAAS,aAAa,CAAC,QAAgB;YACrC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBAChC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;gBACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;gBAEjC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAC3D,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;oBAAE,OAAO,IAAI,CAAC;gBACzD,OAAO,KAAK,CAAC;YACf,CAAC,CAAC,CAAC;QACL,CAAC;QAED,SAAS,kBAAkB,CAAC,IAAY;YACtC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBAChC,MAAM,gBAAgB,GAAG,MAAM,CAAC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