forked from ivov/eslint-plugin-n8n-nodes-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cred-class-name-unsuffixed.ts
45 lines (38 loc) · 1.03 KB
/
cred-class-name-unsuffixed.ts
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
import { utils } from "../ast/utils";
import { id } from "../ast/identifiers";
import { getters } from "../ast/getters";
import { isExemptedFromApiSuffix } from "../ast/utils/apiSuffixExemption";
export default utils.createRule({
name: utils.getRuleName(module),
meta: {
type: "problem",
docs: {
description: "Credential class name must be suffixed with `-Api`.",
recommended: "error",
},
fixable: "code",
schema: [],
messages: {
fixSuffix: "Suffix with '-Api' [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ClassDeclaration(node) {
if (!id.isCredentialClass(node)) return;
if (isExemptedFromApiSuffix(context.getFilename())) return;
const className = getters.getClassName(node);
if (!className) return;
if (!className.value.endsWith("Api")) {
const fixed = utils.addApiSuffix(className.value);
context.report({
messageId: "fixSuffix",
node: className.ast,
fix: (fixer) => fixer.replaceText(className.ast, fixed),
});
}
},
};
},
});