-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcred-class-field-documentation-url-miscased.ts
49 lines (44 loc) · 1.19 KB
/
cred-class-field-documentation-url-miscased.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
45
46
47
48
49
import { camelCase } from "camel-case";
import { utils } from "../ast/utils";
import { id } from "../ast/identifiers";
import { getters } from "../ast/getters";
export default utils.createRule({
name: utils.getRuleName(module),
meta: {
type: "problem",
docs: {
description:
"`documentationUrl` field in credential class must be camel cased. Only applicable to nodes in the main repository.",
recommended: "strict",
},
fixable: "code",
schema: [],
messages: {
useCamelCase: "Change to camelCase [autofixable]",
},
},
defaultOptions: [],
create(context) {
return {
ClassDeclaration(node) {
if (!id.isCredentialClass(node)) return;
const documentationUrl = getters.credClassBody.getDocumentationUrl(
node.body
);
if (!documentationUrl) return;
const camelCasedDocumentationUrl = camelCase(documentationUrl.value);
if (documentationUrl.value !== camelCasedDocumentationUrl) {
context.report({
messageId: "useCamelCase",
node: documentationUrl.ast,
fix: (fixer) =>
fixer.replaceText(
documentationUrl.ast,
`documentationUrl = '${camelCasedDocumentationUrl}';`
),
});
}
},
};
},
});