-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
101 lines (88 loc) · 2.32 KB
/
index.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"use strict";
/**
* Entrypoint copied into `/dist/index.js` during build.
*/
const fs = require("fs");
const path = require("path");
const RULES_DIST_DIR = path.resolve(__dirname, "lib", "rules"); // /dist/lib/rules
const CONFIG_BASE_PROPERTIES = {
env: { es2021: true },
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["n8n-nodes-base"],
};
const DEFAULT_SEVERITY = "error";
const getRuleModule = (rulename) =>
require(path.resolve(RULES_DIST_DIR, rulename)).default;
const ALL_RULE_NAMES = fs
.readdirSync(RULES_DIST_DIR)
.filter((fileName) => fileName.endsWith(".js"))
.map((filename) => filename.replace(/\.js$/, ""));
/**
* All rules exported by this plugin.
*
* ```js
* 'node-class-description-credentials-name-unsuffixed': {
* meta: { ... },
* create: { ... }
* },
* 'node-class-description-display-name-unsuffixed-trigger-node': {
* meta: { ... },
* create: { ... }
* },
* // etc
* ```
*/
const allRuleModules = ALL_RULE_NAMES.reduce((acc, rulename) => {
return {
...acc,
[rulename]: getRuleModule(rulename),
};
}, {});
/**
* Configs exported by this plugin.
*
* ```js
* {
* "all": {
* env: { es2021: true },
* parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
* plugins: [ 'n8n-nodes-base' ],
* rules: {
* 'n8n-nodes-base/cred-class-field-display-name-miscased': 'error',
* // etc
* }
* },
* "community": { ... },
* "credentials": { ... },
* "nodes": { ... },
* "community": { ... },
* }
* ```
*/
const configs = ALL_RULE_NAMES.reduce(
(acc, rulename) => {
const fullRulename = `n8n-nodes-base/${rulename}`;
acc["all"].rules[fullRulename] = DEFAULT_SEVERITY;
if (rulename.startsWith("community-package-json-")) {
acc["community"].rules[fullRulename] = DEFAULT_SEVERITY;
} else if (rulename.startsWith("cred-")) {
acc["credentials"].rules[fullRulename] = DEFAULT_SEVERITY;
} else if (rulename.startsWith("node-")) {
acc["nodes"].rules[fullRulename] = DEFAULT_SEVERITY;
}
return acc;
},
{
all: { ...CONFIG_BASE_PROPERTIES, rules: {} }, // @TODO: Remove
community: { ...CONFIG_BASE_PROPERTIES, rules: {} },
credentials: { ...CONFIG_BASE_PROPERTIES, rules: {} },
nodes: { ...CONFIG_BASE_PROPERTIES, rules: {} },
}
);
module.exports = {
rules: allRuleModules,
configs,
};