-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcontains-word-plugin.mjs
More file actions
55 lines (52 loc) · 1.41 KB
/
contains-word-plugin.mjs
File metadata and controls
55 lines (52 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { PLUGIN_API_VERSION, definePlugin, delta } from "../../src/node-entry.ts";
export default definePlugin({
meta: {
name: "slop-scan-plugin-contains-word",
namespace: "local",
apiVersion: PLUGIN_API_VERSION,
},
rules: {
"contains-word": {
id: "local/contains-word",
family: "local",
severity: "weak",
scope: "file",
requires: ["file.text"],
delta: delta.byPath(),
supports(context) {
return context.scope === "file" && Boolean(context.file);
},
evaluate(context) {
const text = context.runtime.store.getFileFact(context.file.path, "file.text") ?? "";
const options = context.ruleConfig?.options ?? {};
const word = typeof options.word === "string" ? options.word : "danger";
if (!text.includes(word)) {
return [];
}
return [
{
ruleId: "local/contains-word",
family: "local",
severity: "weak",
scope: "file",
path: context.file.path,
message: `Found ${word} in file text`,
evidence: [word],
score: 1,
locations: [{ path: context.file.path, line: 1 }],
},
];
},
},
},
configs: {
recommended: {
rules: {
"local/contains-word": {
enabled: true,
options: { word: "danger" },
},
},
},
},
});