@n8n/eslint-plugin-community-nodes 0.20.0 → 0.22.0
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.
- package/.turbo/turbo-build$colon$unchecked.log +1 -1
- package/README.md +47 -38
- package/dist/plugin.d.ts +54 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +18 -0
- package/dist/plugin.js.map +1 -1
- package/dist/rules/ai-node-package-json.d.ts.map +1 -1
- package/dist/rules/ai-node-package-json.js +4 -3
- package/dist/rules/ai-node-package-json.js.map +1 -1
- package/dist/rules/cred-filename-against-convention.d.ts +2 -0
- package/dist/rules/cred-filename-against-convention.d.ts.map +1 -0
- package/dist/rules/cred-filename-against-convention.js +42 -0
- package/dist/rules/cred-filename-against-convention.js.map +1 -0
- package/dist/rules/icon-prefer-themed-variants.d.ts +2 -0
- package/dist/rules/icon-prefer-themed-variants.d.ts.map +1 -0
- package/dist/rules/icon-prefer-themed-variants.js +53 -0
- package/dist/rules/icon-prefer-themed-variants.js.map +1 -0
- package/dist/rules/icon-validation.d.ts +1 -1
- package/dist/rules/icon-validation.d.ts.map +1 -1
- package/dist/rules/icon-validation.js +4 -25
- package/dist/rules/icon-validation.js.map +1 -1
- package/dist/rules/index.d.ts +10 -1
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +18 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-dangerous-functions.d.ts +2 -0
- package/dist/rules/no-dangerous-functions.d.ts.map +1 -0
- package/dist/rules/no-dangerous-functions.js +121 -0
- package/dist/rules/no-dangerous-functions.js.map +1 -0
- package/dist/rules/no-emoji-in-options.d.ts +2 -0
- package/dist/rules/no-emoji-in-options.d.ts.map +1 -0
- package/dist/rules/no-emoji-in-options.js +86 -0
- package/dist/rules/no-emoji-in-options.js.map +1 -0
- package/dist/rules/node-class-description-name-camelcase.d.ts +2 -0
- package/dist/rules/node-class-description-name-camelcase.d.ts.map +1 -0
- package/dist/rules/node-class-description-name-camelcase.js +92 -0
- package/dist/rules/node-class-description-name-camelcase.js.map +1 -0
- package/dist/rules/node-filename-against-convention.d.ts +2 -0
- package/dist/rules/node-filename-against-convention.d.ts.map +1 -0
- package/dist/rules/node-filename-against-convention.js +61 -0
- package/dist/rules/node-filename-against-convention.js.map +1 -0
- package/dist/rules/node-registration-complete.d.ts +2 -0
- package/dist/rules/node-registration-complete.d.ts.map +1 -0
- package/dist/rules/node-registration-complete.js +60 -0
- package/dist/rules/node-registration-complete.js.map +1 -0
- package/dist/rules/require-version.d.ts +2 -0
- package/dist/rules/require-version.d.ts.map +1 -0
- package/dist/rules/require-version.js +50 -0
- package/dist/rules/require-version.js.map +1 -0
- package/dist/rules/valid-author.d.ts +2 -0
- package/dist/rules/valid-author.d.ts.map +1 -0
- package/dist/rules/valid-author.js +89 -0
- package/dist/rules/valid-author.js.map +1 -0
- package/dist/rules/valid-peer-dependencies.d.ts.map +1 -1
- package/dist/rules/valid-peer-dependencies.js +5 -3
- package/dist/rules/valid-peer-dependencies.js.map +1 -1
- package/dist/typecheck.tsbuildinfo +1 -0
- package/dist/utils/file-utils.d.ts +7 -2
- package/dist/utils/file-utils.d.ts.map +1 -1
- package/dist/utils/file-utils.js +47 -10
- package/dist/utils/file-utils.js.map +1 -1
- package/docs/rules/cred-filename-against-convention.md +42 -0
- package/docs/rules/icon-prefer-themed-variants.md +71 -0
- package/docs/rules/icon-validation.md +5 -3
- package/docs/rules/no-dangerous-functions.md +41 -0
- package/docs/rules/no-emoji-in-options.md +60 -0
- package/docs/rules/node-class-description-name-camelcase.md +41 -0
- package/docs/rules/node-filename-against-convention.md +50 -0
- package/docs/rules/node-registration-complete.md +46 -0
- package/docs/rules/require-version.md +51 -0
- package/docs/rules/valid-author.md +60 -0
- package/docs/rules/valid-peer-dependencies.md +1 -1
- package/package.json +4 -4
- package/src/plugin.ts +18 -0
- package/src/rules/ai-node-package-json.test.ts +5 -0
- package/src/rules/ai-node-package-json.ts +4 -3
- package/src/rules/cred-filename-against-convention.test.ts +72 -0
- package/src/rules/cred-filename-against-convention.ts +48 -0
- package/src/rules/icon-prefer-themed-variants.test.ts +128 -0
- package/src/rules/icon-prefer-themed-variants.ts +70 -0
- package/src/rules/icon-validation.test.ts +10 -0
- package/src/rules/icon-validation.ts +4 -28
- package/src/rules/index.ts +18 -0
- package/src/rules/no-dangerous-functions.test.ts +83 -0
- package/src/rules/no-dangerous-functions.ts +155 -0
- package/src/rules/no-emoji-in-options.test.ts +157 -0
- package/src/rules/no-emoji-in-options.ts +105 -0
- package/src/rules/node-class-description-name-camelcase.test.ts +121 -0
- package/src/rules/node-class-description-name-camelcase.ts +114 -0
- package/src/rules/node-filename-against-convention.test.ts +115 -0
- package/src/rules/node-filename-against-convention.ts +76 -0
- package/src/rules/node-registration-complete.test.ts +87 -0
- package/src/rules/node-registration-complete.ts +79 -0
- package/src/rules/require-version.test.ts +90 -0
- package/src/rules/require-version.ts +62 -0
- package/src/rules/valid-author.test.ts +108 -0
- package/src/rules/valid-author.ts +100 -0
- package/src/rules/valid-peer-dependencies.test.ts +5 -0
- package/src/rules/valid-peer-dependencies.ts +5 -3
- package/src/utils/file-utils.ts +58 -11
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
|
|
3
|
+
import { NoEmojiInOptionsRule } from './no-emoji-in-options.js';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester();
|
|
6
|
+
|
|
7
|
+
function createNodeCode(body: string): string {
|
|
8
|
+
return `
|
|
9
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
10
|
+
|
|
11
|
+
export class TestNode implements INodeType {
|
|
12
|
+
description: INodeTypeDescription = {
|
|
13
|
+
${body}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ruleTester.run('no-emoji-in-options', NoEmojiInOptionsRule, {
|
|
20
|
+
valid: [
|
|
21
|
+
{
|
|
22
|
+
name: 'class that does not implement INodeType',
|
|
23
|
+
filename: '/tmp/TestNode.node.ts',
|
|
24
|
+
code: `
|
|
25
|
+
export class NotANode {
|
|
26
|
+
description = { displayName: '🚀 Rocket' };
|
|
27
|
+
}
|
|
28
|
+
`,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'non .node.ts file is ignored',
|
|
32
|
+
filename: '/tmp/helper.ts',
|
|
33
|
+
code: `
|
|
34
|
+
export class TestNode {
|
|
35
|
+
description = { displayName: '🚀 Rocket' };
|
|
36
|
+
}
|
|
37
|
+
`,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'node and option labels without emoji',
|
|
41
|
+
filename: '/tmp/TestNode.node.ts',
|
|
42
|
+
code: createNodeCode(`
|
|
43
|
+
displayName: 'Test Node',
|
|
44
|
+
name: 'testNode',
|
|
45
|
+
defaults: { name: 'Test Node' },
|
|
46
|
+
properties: [
|
|
47
|
+
{
|
|
48
|
+
displayName: 'Operation',
|
|
49
|
+
name: 'operation',
|
|
50
|
+
type: 'options',
|
|
51
|
+
options: [
|
|
52
|
+
{ name: 'Create', value: 'create' },
|
|
53
|
+
{ name: 'Delete', value: 'delete' },
|
|
54
|
+
],
|
|
55
|
+
default: 'create',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
`),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'accented and non-latin characters are allowed',
|
|
62
|
+
filename: '/tmp/TestNode.node.ts',
|
|
63
|
+
code: createNodeCode(`
|
|
64
|
+
displayName: 'Créer un café',
|
|
65
|
+
name: 'testNode',
|
|
66
|
+
properties: [
|
|
67
|
+
{
|
|
68
|
+
displayName: '日本語',
|
|
69
|
+
name: 'field',
|
|
70
|
+
type: 'string',
|
|
71
|
+
default: '',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
`),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
invalid: [
|
|
78
|
+
{
|
|
79
|
+
name: 'emoji in node displayName',
|
|
80
|
+
filename: '/tmp/TestNode.node.ts',
|
|
81
|
+
code: createNodeCode(`
|
|
82
|
+
displayName: '🚀 Rocket Node',
|
|
83
|
+
name: 'testNode',
|
|
84
|
+
properties: [],
|
|
85
|
+
`),
|
|
86
|
+
errors: [{ messageId: 'emojiInOption', data: { key: 'displayName', emoji: '🚀' } }],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'emoji in option name within options array',
|
|
90
|
+
filename: '/tmp/TestNode.node.ts',
|
|
91
|
+
code: createNodeCode(`
|
|
92
|
+
displayName: 'Test Node',
|
|
93
|
+
name: 'testNode',
|
|
94
|
+
properties: [
|
|
95
|
+
{
|
|
96
|
+
displayName: 'Operation',
|
|
97
|
+
name: 'operation',
|
|
98
|
+
type: 'options',
|
|
99
|
+
options: [
|
|
100
|
+
{ name: '✅ Create', value: 'create' },
|
|
101
|
+
{ name: 'Delete', value: 'delete' },
|
|
102
|
+
],
|
|
103
|
+
default: 'create',
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
`),
|
|
107
|
+
errors: [{ messageId: 'emojiInOption', data: { key: 'name', emoji: '✅' } }],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'emoji in property displayName',
|
|
111
|
+
filename: '/tmp/TestNode.node.ts',
|
|
112
|
+
code: createNodeCode(`
|
|
113
|
+
displayName: 'Test Node',
|
|
114
|
+
name: 'testNode',
|
|
115
|
+
properties: [
|
|
116
|
+
{
|
|
117
|
+
displayName: 'First Name 🙂',
|
|
118
|
+
name: 'firstName',
|
|
119
|
+
type: 'string',
|
|
120
|
+
default: '',
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
`),
|
|
124
|
+
errors: [{ messageId: 'emojiInOption', data: { key: 'displayName', emoji: '🙂' } }],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'flag emoji built from regional indicators',
|
|
128
|
+
filename: '/tmp/TestNode.node.ts',
|
|
129
|
+
code: createNodeCode(`
|
|
130
|
+
displayName: 'Region 🇺🇸',
|
|
131
|
+
name: 'testNode',
|
|
132
|
+
properties: [],
|
|
133
|
+
`),
|
|
134
|
+
errors: [{ messageId: 'emojiInOption', data: { key: 'displayName', emoji: '🇺 🇸' } }],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'multiple emoji values reported separately',
|
|
138
|
+
filename: '/tmp/TestNode.node.ts',
|
|
139
|
+
code: createNodeCode(`
|
|
140
|
+
displayName: '🚀 Node',
|
|
141
|
+
name: 'testNode',
|
|
142
|
+
properties: [
|
|
143
|
+
{
|
|
144
|
+
displayName: 'Field 🎉',
|
|
145
|
+
name: 'field',
|
|
146
|
+
type: 'string',
|
|
147
|
+
default: '',
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
`),
|
|
151
|
+
errors: [
|
|
152
|
+
{ messageId: 'emojiInOption', data: { key: 'displayName', emoji: '🚀' } },
|
|
153
|
+
{ messageId: 'emojiInOption', data: { key: 'displayName', emoji: '🎉' } },
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
isNodeTypeClass,
|
|
6
|
+
findClassProperty,
|
|
7
|
+
getStringLiteralValue,
|
|
8
|
+
isFileType,
|
|
9
|
+
createRule,
|
|
10
|
+
} from '../utils/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Matches emoji characters: pictographs (😀, 🚀, ✉️, etc.) and regional
|
|
14
|
+
* indicator symbols that compose flag emoji (🇺🇸).
|
|
15
|
+
*/
|
|
16
|
+
const EMOJI_REGEX = /(\p{Extended_Pictographic}|\p{Regional_Indicator})/gu;
|
|
17
|
+
|
|
18
|
+
/** Keys whose string values are surfaced to users as labels. */
|
|
19
|
+
const LABEL_KEYS = new Set(['name', 'displayName']);
|
|
20
|
+
|
|
21
|
+
export const NoEmojiInOptionsRule = createRule({
|
|
22
|
+
name: 'no-emoji-in-options',
|
|
23
|
+
meta: {
|
|
24
|
+
type: 'problem',
|
|
25
|
+
docs: {
|
|
26
|
+
description: 'Disallow emoji characters in node option name and displayName values',
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
emojiInOption: 'Emoji characters are not allowed in "{{ key }}" values. Found: {{ emoji }}.',
|
|
30
|
+
},
|
|
31
|
+
schema: [],
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
if (!isFileType(context.filename, '.node.ts')) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const checkLabelValue = (key: string, valueNode: TSESTree.Node): void => {
|
|
40
|
+
const value = getStringLiteralValue(valueNode);
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const matches = value.match(EMOJI_REGEX);
|
|
46
|
+
if (!matches) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
context.report({
|
|
51
|
+
node: valueNode,
|
|
52
|
+
messageId: 'emojiInOption',
|
|
53
|
+
data: {
|
|
54
|
+
key,
|
|
55
|
+
emoji: [...new Set(matches)].join(' '),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const traverse = (node: TSESTree.Node): void => {
|
|
61
|
+
if (node.type === AST_NODE_TYPES.ObjectExpression) {
|
|
62
|
+
for (const property of node.properties) {
|
|
63
|
+
if (
|
|
64
|
+
property.type === AST_NODE_TYPES.Property &&
|
|
65
|
+
property.key.type === AST_NODE_TYPES.Identifier &&
|
|
66
|
+
LABEL_KEYS.has(property.key.name)
|
|
67
|
+
) {
|
|
68
|
+
checkLabelValue(property.key.name, property.value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const key in node) {
|
|
74
|
+
if (key === 'parent') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const child = node[key as keyof TSESTree.Node] as unknown;
|
|
78
|
+
if (Array.isArray(child)) {
|
|
79
|
+
for (const item of child) {
|
|
80
|
+
if (item && typeof item === 'object' && 'type' in item) {
|
|
81
|
+
traverse(item as TSESTree.Node);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else if (child && typeof child === 'object' && 'type' in child) {
|
|
85
|
+
traverse(child as TSESTree.Node);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
ClassDeclaration(node) {
|
|
92
|
+
if (!isNodeTypeClass(node)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const descriptionProperty = findClassProperty(node, 'description');
|
|
97
|
+
if (!descriptionProperty?.value) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
traverse(descriptionProperty.value);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
|
|
3
|
+
import { NodeClassDescriptionNameCamelCaseRule } from './node-class-description-name-camelcase.js';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester();
|
|
6
|
+
|
|
7
|
+
function createNodeCode(name: string): string {
|
|
8
|
+
return `
|
|
9
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
10
|
+
|
|
11
|
+
export class TestNode implements INodeType {
|
|
12
|
+
description: INodeTypeDescription = {
|
|
13
|
+
displayName: 'Test Node',
|
|
14
|
+
name: '${name}',
|
|
15
|
+
group: ['input'],
|
|
16
|
+
version: 1,
|
|
17
|
+
description: 'A test node',
|
|
18
|
+
defaults: { name: 'Test Node' },
|
|
19
|
+
inputs: [],
|
|
20
|
+
outputs: [],
|
|
21
|
+
properties: [],
|
|
22
|
+
};
|
|
23
|
+
}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function createNodeCodeWithoutName(): string {
|
|
27
|
+
return `
|
|
28
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
29
|
+
|
|
30
|
+
export class TestNode implements INodeType {
|
|
31
|
+
description: INodeTypeDescription = {
|
|
32
|
+
displayName: 'Test Node',
|
|
33
|
+
group: ['input'],
|
|
34
|
+
version: 1,
|
|
35
|
+
description: 'A test node',
|
|
36
|
+
defaults: { name: 'Test Node' },
|
|
37
|
+
inputs: [],
|
|
38
|
+
outputs: [],
|
|
39
|
+
properties: [],
|
|
40
|
+
};
|
|
41
|
+
}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createRegularClass(): string {
|
|
45
|
+
return `
|
|
46
|
+
export class SomeHelper {
|
|
47
|
+
name = 'My Helper';
|
|
48
|
+
}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
ruleTester.run('node-class-description-name-camelcase', NodeClassDescriptionNameCamelCaseRule, {
|
|
52
|
+
valid: [
|
|
53
|
+
{
|
|
54
|
+
name: 'single lowercase word',
|
|
55
|
+
filename: '/tmp/Github.node.ts',
|
|
56
|
+
code: createNodeCode('github'),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'camelCase multi-word name',
|
|
60
|
+
filename: '/tmp/GoogleSheets.node.ts',
|
|
61
|
+
code: createNodeCode('googleSheets'),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'camelCase name with digits',
|
|
65
|
+
filename: '/tmp/Oauth2.node.ts',
|
|
66
|
+
code: createNodeCode('myNode2'),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'class not implementing INodeType is ignored',
|
|
70
|
+
filename: '/tmp/Github.node.ts',
|
|
71
|
+
code: createRegularClass(),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'non-.node.ts file is ignored',
|
|
75
|
+
filename: '/tmp/Github.ts',
|
|
76
|
+
code: createNodeCode('My Node'),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'missing description.name is ignored',
|
|
80
|
+
filename: '/tmp/Github.node.ts',
|
|
81
|
+
code: createNodeCodeWithoutName(),
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
invalid: [
|
|
85
|
+
{
|
|
86
|
+
name: 'PascalCase first letter is lowercased',
|
|
87
|
+
filename: '/tmp/Github.node.ts',
|
|
88
|
+
code: createNodeCode('MyNode'),
|
|
89
|
+
errors: [{ messageId: 'notCamelCase', data: { value: 'MyNode' } }],
|
|
90
|
+
output: createNodeCode('myNode'),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'spaces are removed and camelCased',
|
|
94
|
+
filename: '/tmp/Github.node.ts',
|
|
95
|
+
code: createNodeCode('My Node'),
|
|
96
|
+
errors: [{ messageId: 'notCamelCase', data: { value: 'My Node' } }],
|
|
97
|
+
output: createNodeCode('myNode'),
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'hyphen separators are removed and camelCased',
|
|
101
|
+
filename: '/tmp/Github.node.ts',
|
|
102
|
+
code: createNodeCode('my-node'),
|
|
103
|
+
errors: [{ messageId: 'notCamelCase', data: { value: 'my-node' } }],
|
|
104
|
+
output: createNodeCode('myNode'),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'underscore separators are removed and camelCased',
|
|
108
|
+
filename: '/tmp/Github.node.ts',
|
|
109
|
+
code: createNodeCode('my_cool_node'),
|
|
110
|
+
errors: [{ messageId: 'notCamelCase', data: { value: 'my_cool_node' } }],
|
|
111
|
+
output: createNodeCode('myCoolNode'),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'names starting with a digit are reported without an autofix',
|
|
115
|
+
filename: '/tmp/Github.node.ts',
|
|
116
|
+
code: createNodeCode('123node'),
|
|
117
|
+
errors: [{ messageId: 'notCamelCase', data: { value: '123node' } }],
|
|
118
|
+
output: null,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
isNodeTypeClass,
|
|
5
|
+
findClassProperty,
|
|
6
|
+
findObjectProperty,
|
|
7
|
+
getStringLiteralValue,
|
|
8
|
+
isFileType,
|
|
9
|
+
createRule,
|
|
10
|
+
} from '../utils/index.js';
|
|
11
|
+
|
|
12
|
+
// `description.name` must be camelCase: a lowercase letter followed by
|
|
13
|
+
// letters/digits, with no separators.
|
|
14
|
+
const CAMEL_CASE_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Converts an arbitrary node name to camelCase by splitting on any
|
|
18
|
+
* non-alphanumeric separators, upper-casing the first character of each
|
|
19
|
+
* subsequent segment, and lower-casing the very first character.
|
|
20
|
+
* Examples: `My Node` -> `myNode`, `my-node` -> `myNode`, `GitHub` -> `gitHub`.
|
|
21
|
+
*/
|
|
22
|
+
function toCamelCase(value: string): string {
|
|
23
|
+
const segments = value.split(/[^a-zA-Z0-9]+/).filter(Boolean);
|
|
24
|
+
if (segments.length === 0) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const joined = segments
|
|
29
|
+
.map((segment, index) =>
|
|
30
|
+
index === 0 ? segment : segment.charAt(0).toUpperCase() + segment.slice(1),
|
|
31
|
+
)
|
|
32
|
+
.join('');
|
|
33
|
+
|
|
34
|
+
return joined.charAt(0).toLowerCase() + joined.slice(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Serialize a value as a string literal using the original quote character,
|
|
38
|
+
// escaping any characters that would otherwise break the literal so the
|
|
39
|
+
// autofix never emits invalid code.
|
|
40
|
+
function toStringLiteral(value: string, quote: string): string {
|
|
41
|
+
const escaped = value
|
|
42
|
+
.replace(/\\/g, '\\\\')
|
|
43
|
+
.replace(/\n/g, '\\n')
|
|
44
|
+
.replace(/\r/g, '\\r')
|
|
45
|
+
.split(quote)
|
|
46
|
+
.join(`\\${quote}`);
|
|
47
|
+
return `${quote}${escaped}${quote}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const NodeClassDescriptionNameCamelCaseRule = createRule({
|
|
51
|
+
name: 'node-class-description-name-camelcase',
|
|
52
|
+
meta: {
|
|
53
|
+
type: 'problem',
|
|
54
|
+
docs: {
|
|
55
|
+
description: 'Node class `description.name` must be camelCase',
|
|
56
|
+
},
|
|
57
|
+
messages: {
|
|
58
|
+
notCamelCase: "Node `description.name` '{{value}}' must be camelCase",
|
|
59
|
+
},
|
|
60
|
+
fixable: 'code',
|
|
61
|
+
schema: [],
|
|
62
|
+
},
|
|
63
|
+
defaultOptions: [],
|
|
64
|
+
create(context) {
|
|
65
|
+
if (!isFileType(context.filename, '.node.ts')) {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
ClassDeclaration(node) {
|
|
71
|
+
if (!isNodeTypeClass(node)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const descriptionProperty = findClassProperty(node, 'description');
|
|
76
|
+
if (descriptionProperty?.value?.type !== TSESTree.AST_NODE_TYPES.ObjectExpression) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const nameProperty = findObjectProperty(descriptionProperty.value, 'name');
|
|
81
|
+
if (!nameProperty) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const nameValue = getStringLiteralValue(nameProperty.value);
|
|
86
|
+
if (nameValue === null) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (CAMEL_CASE_PATTERN.test(nameValue)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const valueNode = nameProperty.value;
|
|
95
|
+
const fixedValue = toCamelCase(nameValue);
|
|
96
|
+
// Only offer an autofix when it actually yields a valid camelCase
|
|
97
|
+
// value (e.g. names starting with a digit cannot be repaired).
|
|
98
|
+
const canFix = fixedValue !== nameValue && CAMEL_CASE_PATTERN.test(fixedValue);
|
|
99
|
+
|
|
100
|
+
context.report({
|
|
101
|
+
node: valueNode,
|
|
102
|
+
messageId: 'notCamelCase',
|
|
103
|
+
data: { value: nameValue },
|
|
104
|
+
fix: canFix
|
|
105
|
+
? (fixer) => {
|
|
106
|
+
const quote = context.sourceCode.getText(valueNode).charAt(0);
|
|
107
|
+
return fixer.replaceText(valueNode, toStringLiteral(fixedValue, quote));
|
|
108
|
+
}
|
|
109
|
+
: undefined,
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
|
|
3
|
+
import { NodeFilenameAgainstConventionRule } from './node-filename-against-convention.js';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester();
|
|
6
|
+
|
|
7
|
+
function createNodeCode(name: string): string {
|
|
8
|
+
return `
|
|
9
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
10
|
+
|
|
11
|
+
export class TestNode implements INodeType {
|
|
12
|
+
description: INodeTypeDescription = {
|
|
13
|
+
displayName: 'Test Node',
|
|
14
|
+
name: '${name}',
|
|
15
|
+
group: ['input'],
|
|
16
|
+
version: 1,
|
|
17
|
+
description: 'A test node',
|
|
18
|
+
defaults: { name: 'Test Node' },
|
|
19
|
+
inputs: [],
|
|
20
|
+
outputs: [],
|
|
21
|
+
properties: [],
|
|
22
|
+
};
|
|
23
|
+
}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function createNodeCodeWithoutName(): string {
|
|
27
|
+
return `
|
|
28
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
29
|
+
|
|
30
|
+
export class TestNode implements INodeType {
|
|
31
|
+
description: INodeTypeDescription = {
|
|
32
|
+
displayName: 'Test Node',
|
|
33
|
+
group: ['input'],
|
|
34
|
+
version: 1,
|
|
35
|
+
description: 'A test node',
|
|
36
|
+
defaults: { name: 'Test Node' },
|
|
37
|
+
inputs: [],
|
|
38
|
+
outputs: [],
|
|
39
|
+
properties: [],
|
|
40
|
+
};
|
|
41
|
+
}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createRegularClass(): string {
|
|
45
|
+
return `
|
|
46
|
+
export class SomeHelper {
|
|
47
|
+
name = 'github';
|
|
48
|
+
}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
ruleTester.run('node-filename-against-convention', NodeFilenameAgainstConventionRule, {
|
|
52
|
+
valid: [
|
|
53
|
+
{
|
|
54
|
+
name: 'filename matches PascalCased description.name',
|
|
55
|
+
filename: '/tmp/Github.node.ts',
|
|
56
|
+
code: createNodeCode('github'),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'filename with version suffix is accepted',
|
|
60
|
+
filename: '/tmp/GithubV2.node.ts',
|
|
61
|
+
code: createNodeCode('github'),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'filename with multi-digit version suffix is accepted',
|
|
65
|
+
filename: '/tmp/GithubV10.node.ts',
|
|
66
|
+
code: createNodeCode('github'),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'multi-word camelCase name maps to PascalCase filename',
|
|
70
|
+
filename: '/tmp/GoogleSheets.node.ts',
|
|
71
|
+
code: createNodeCode('googleSheets'),
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'class not implementing INodeType is ignored',
|
|
75
|
+
filename: '/tmp/Github.node.ts',
|
|
76
|
+
code: createRegularClass(),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'non-.node.ts file is ignored',
|
|
80
|
+
filename: '/tmp/Github.ts',
|
|
81
|
+
code: createNodeCode('mismatch'),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'missing description.name is ignored',
|
|
85
|
+
filename: '/tmp/Github.node.ts',
|
|
86
|
+
code: createNodeCodeWithoutName(),
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
invalid: [
|
|
90
|
+
{
|
|
91
|
+
name: 'filename does not match description.name',
|
|
92
|
+
filename: '/tmp/Github.node.ts',
|
|
93
|
+
code: createNodeCode('gitlab'),
|
|
94
|
+
errors: [{ messageId: 'renameFile', data: { expected: 'Gitlab.node.ts' } }],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'filename is lowercased',
|
|
98
|
+
filename: '/tmp/github.node.ts',
|
|
99
|
+
code: createNodeCode('github'),
|
|
100
|
+
errors: [{ messageId: 'renameFile', data: { expected: 'Github.node.ts' } }],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'filename has wrong internal casing',
|
|
104
|
+
filename: '/tmp/GitHub.node.ts',
|
|
105
|
+
code: createNodeCode('github'),
|
|
106
|
+
errors: [{ messageId: 'renameFile', data: { expected: 'Github.node.ts' } }],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'version suffix does not excuse a mismatched base name',
|
|
110
|
+
filename: '/tmp/GitlabV2.node.ts',
|
|
111
|
+
code: createNodeCode('github'),
|
|
112
|
+
errors: [{ messageId: 'renameFile', data: { expected: 'Github.node.ts' } }],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
isNodeTypeClass,
|
|
6
|
+
findClassProperty,
|
|
7
|
+
findObjectProperty,
|
|
8
|
+
getStringLiteralValue,
|
|
9
|
+
isFileType,
|
|
10
|
+
createRule,
|
|
11
|
+
} from '../utils/index.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Converts a `description.name` to the expected node file basename by
|
|
15
|
+
* upper-casing the first character. The source of truth is `description.name`,
|
|
16
|
+
* not the class name. Example: `github` -> `Github`.
|
|
17
|
+
*/
|
|
18
|
+
function toExpectedBaseName(name: string): string {
|
|
19
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const NodeFilenameAgainstConventionRule = createRule({
|
|
23
|
+
name: 'node-filename-against-convention',
|
|
24
|
+
meta: {
|
|
25
|
+
type: 'problem',
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Node filename must match the node `description.name`',
|
|
28
|
+
},
|
|
29
|
+
messages: {
|
|
30
|
+
renameFile: 'Node filename must match `description.name`. Rename file to "{{expected}}".',
|
|
31
|
+
},
|
|
32
|
+
schema: [],
|
|
33
|
+
},
|
|
34
|
+
defaultOptions: [],
|
|
35
|
+
create(context) {
|
|
36
|
+
if (!isFileType(context.filename, '.node.ts')) {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
ClassDeclaration(node) {
|
|
42
|
+
if (!isNodeTypeClass(node)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const descriptionProperty = findClassProperty(node, 'description');
|
|
47
|
+
if (descriptionProperty?.value?.type !== TSESTree.AST_NODE_TYPES.ObjectExpression) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const nameProperty = findObjectProperty(descriptionProperty.value, 'name');
|
|
52
|
+
if (!nameProperty) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const name = getStringLiteralValue(nameProperty.value);
|
|
57
|
+
if (!name) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const expectedBaseName = toExpectedBaseName(name);
|
|
62
|
+
// Strip the `.node.ts` extension and any trailing `V<digits>` version
|
|
63
|
+
// suffix so versioned files (e.g. `GithubV2.node.ts`) are accepted.
|
|
64
|
+
const actualBaseName = path.basename(context.filename, '.node.ts').replace(/V\d+$/, '');
|
|
65
|
+
|
|
66
|
+
if (actualBaseName !== expectedBaseName) {
|
|
67
|
+
context.report({
|
|
68
|
+
node: nameProperty.value,
|
|
69
|
+
messageId: 'renameFile',
|
|
70
|
+
data: { expected: `${expectedBaseName}.node.ts` },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
});
|