@n8n/eslint-plugin-community-nodes 0.11.0 → 0.13.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.log +1 -1
- package/README.md +5 -1
- package/dist/plugin.d.ts +30 -6
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +10 -2
- package/dist/plugin.js.map +1 -1
- package/dist/rules/index.d.ts +5 -0
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +10 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/missing-paired-item.d.ts +16 -0
- package/dist/rules/missing-paired-item.d.ts.map +1 -0
- package/dist/rules/missing-paired-item.js +121 -0
- package/dist/rules/missing-paired-item.js.map +1 -0
- package/dist/rules/no-forbidden-lifecycle-scripts.d.ts +2 -0
- package/dist/rules/no-forbidden-lifecycle-scripts.d.ts.map +1 -0
- package/dist/rules/no-forbidden-lifecycle-scripts.js +59 -0
- package/dist/rules/no-forbidden-lifecycle-scripts.js.map +1 -0
- package/dist/rules/node-class-description-icon-missing.d.ts +1 -0
- package/dist/rules/node-class-description-icon-missing.d.ts.map +1 -1
- package/dist/rules/node-class-description-icon-missing.js +6 -1
- package/dist/rules/node-class-description-icon-missing.js.map +1 -1
- package/dist/rules/require-community-node-keyword.d.ts +2 -0
- package/dist/rules/require-community-node-keyword.d.ts.map +1 -0
- package/dist/rules/require-community-node-keyword.js +65 -0
- package/dist/rules/require-community-node-keyword.js.map +1 -0
- package/dist/rules/require-continue-on-fail.d.ts +2 -0
- package/dist/rules/require-continue-on-fail.d.ts.map +1 -0
- package/dist/rules/require-continue-on-fail.js +76 -0
- package/dist/rules/require-continue-on-fail.js.map +1 -0
- package/dist/rules/require-node-description-fields.d.ts +2 -0
- package/dist/rules/require-node-description-fields.d.ts.map +1 -0
- package/dist/rules/require-node-description-fields.js +58 -0
- package/dist/rules/require-node-description-fields.js.map +1 -0
- package/docs/rules/missing-paired-item.md +70 -0
- package/docs/rules/no-forbidden-lifecycle-scripts.md +46 -0
- package/docs/rules/node-class-description-icon-missing.md +1 -1
- package/docs/rules/require-community-node-keyword.md +45 -0
- package/docs/rules/require-continue-on-fail.md +56 -0
- package/docs/rules/require-node-description-fields.md +46 -0
- package/package.json +3 -3
- package/src/plugin.ts +10 -2
- package/src/rules/index.ts +10 -0
- package/src/rules/missing-paired-item.test.ts +229 -0
- package/src/rules/missing-paired-item.ts +149 -0
- package/src/rules/no-forbidden-lifecycle-scripts.test.ts +103 -0
- package/src/rules/no-forbidden-lifecycle-scripts.ts +69 -0
- package/src/rules/node-class-description-icon-missing.ts +7 -1
- package/src/rules/require-community-node-keyword.test.ts +82 -0
- package/src/rules/require-community-node-keyword.ts +78 -0
- package/src/rules/require-continue-on-fail.test.ts +129 -0
- package/src/rules/require-continue-on-fail.ts +88 -0
- package/src/rules/require-node-description-fields.test.ts +171 -0
- package/src/rules/require-node-description-fields.ts +77 -0
- package/tsconfig.build.tsbuildinfo +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
3
|
+
|
|
4
|
+
import { createRule, findJsonProperty } from '../utils/index.js';
|
|
5
|
+
|
|
6
|
+
const REQUIRED_KEYWORD = 'n8n-community-node-package';
|
|
7
|
+
|
|
8
|
+
export const RequireCommunityNodeKeywordRule = createRule({
|
|
9
|
+
name: 'require-community-node-keyword',
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'problem',
|
|
12
|
+
docs: {
|
|
13
|
+
description:
|
|
14
|
+
'Require the "n8n-community-node-package" keyword in community node package.json',
|
|
15
|
+
},
|
|
16
|
+
fixable: 'code',
|
|
17
|
+
messages: {
|
|
18
|
+
missingKeyword: `The "keywords" array must include "${REQUIRED_KEYWORD}". This keyword is required for n8n to discover community node packages.`,
|
|
19
|
+
missingKeywordsArray: `The package.json must have a "keywords" array containing "${REQUIRED_KEYWORD}".`,
|
|
20
|
+
},
|
|
21
|
+
schema: [],
|
|
22
|
+
},
|
|
23
|
+
defaultOptions: [],
|
|
24
|
+
create(context) {
|
|
25
|
+
if (!context.filename.endsWith('package.json')) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
ObjectExpression(node: TSESTree.ObjectExpression) {
|
|
31
|
+
if (node.parent?.type !== AST_NODE_TYPES.ExpressionStatement) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const keywordsProp = findJsonProperty(node, 'keywords');
|
|
36
|
+
|
|
37
|
+
if (!keywordsProp) {
|
|
38
|
+
context.report({
|
|
39
|
+
node,
|
|
40
|
+
messageId: 'missingKeywordsArray',
|
|
41
|
+
fix(fixer) {
|
|
42
|
+
const lastProp = node.properties[node.properties.length - 1];
|
|
43
|
+
if (!lastProp) {
|
|
44
|
+
return fixer.replaceText(node, `{ "keywords": ["${REQUIRED_KEYWORD}"] }`);
|
|
45
|
+
}
|
|
46
|
+
return fixer.insertTextAfter(lastProp, `, "keywords": ["${REQUIRED_KEYWORD}"]`);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (keywordsProp.value.type !== AST_NODE_TYPES.ArrayExpression) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const keywordsArray = keywordsProp.value;
|
|
57
|
+
const hasRequiredKeyword = keywordsArray.elements.some(
|
|
58
|
+
(element) =>
|
|
59
|
+
element?.type === AST_NODE_TYPES.Literal && element.value === REQUIRED_KEYWORD,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (!hasRequiredKeyword) {
|
|
63
|
+
context.report({
|
|
64
|
+
node: keywordsProp,
|
|
65
|
+
messageId: 'missingKeyword',
|
|
66
|
+
fix(fixer) {
|
|
67
|
+
const lastElement = keywordsArray.elements[keywordsArray.elements.length - 1];
|
|
68
|
+
if (!lastElement) {
|
|
69
|
+
return fixer.replaceText(keywordsArray, `["${REQUIRED_KEYWORD}"]`);
|
|
70
|
+
}
|
|
71
|
+
return fixer.insertTextAfter(lastElement, `, "${REQUIRED_KEYWORD}"`);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
|
|
3
|
+
import { RequireContinueOnFailRule } from './require-continue-on-fail.js';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester();
|
|
6
|
+
|
|
7
|
+
function createNodeWithExecute(executeBody: string): string {
|
|
8
|
+
return `
|
|
9
|
+
import type { INodeType, INodeTypeDescription, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
10
|
+
|
|
11
|
+
export class TestNode implements INodeType {
|
|
12
|
+
description: INodeTypeDescription = {
|
|
13
|
+
displayName: 'Test Node',
|
|
14
|
+
name: 'testNode',
|
|
15
|
+
group: ['input'],
|
|
16
|
+
version: 1,
|
|
17
|
+
description: 'A test node',
|
|
18
|
+
defaults: { name: 'Test Node' },
|
|
19
|
+
inputs: ['main'],
|
|
20
|
+
outputs: ['main'],
|
|
21
|
+
properties: [],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
25
|
+
${executeBody}
|
|
26
|
+
}
|
|
27
|
+
}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ruleTester.run('require-continue-on-fail', RequireContinueOnFailRule, {
|
|
31
|
+
valid: [
|
|
32
|
+
{
|
|
33
|
+
name: 'node with continueOnFail in catch block',
|
|
34
|
+
code: createNodeWithExecute(`
|
|
35
|
+
const items = this.getInputData();
|
|
36
|
+
const returnData: INodeExecutionData[] = [];
|
|
37
|
+
for (let i = 0; i < items.length; i++) {
|
|
38
|
+
try {
|
|
39
|
+
returnData.push({ json: { result: true } });
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (this.continueOnFail()) {
|
|
42
|
+
returnData.push({ json: { error: error.message } });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [returnData];
|
|
49
|
+
`),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'non-node class with execute method (should be ignored)',
|
|
53
|
+
code: `
|
|
54
|
+
export class RegularClass {
|
|
55
|
+
async execute() {
|
|
56
|
+
return [[]];
|
|
57
|
+
}
|
|
58
|
+
}`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'node class without execute method (should be ignored)',
|
|
62
|
+
code: `
|
|
63
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
64
|
+
|
|
65
|
+
export class TestNode implements INodeType {
|
|
66
|
+
description: INodeTypeDescription = {
|
|
67
|
+
displayName: 'Test Node',
|
|
68
|
+
name: 'testNode',
|
|
69
|
+
group: ['input'],
|
|
70
|
+
version: 1,
|
|
71
|
+
description: 'A test node',
|
|
72
|
+
defaults: { name: 'Test Node' },
|
|
73
|
+
inputs: ['main'],
|
|
74
|
+
outputs: ['main'],
|
|
75
|
+
properties: [],
|
|
76
|
+
};
|
|
77
|
+
}`,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'node extending Node base class with continueOnFail',
|
|
81
|
+
code: `
|
|
82
|
+
import { Node } from 'n8n-workflow';
|
|
83
|
+
|
|
84
|
+
export class TestNode extends Node {
|
|
85
|
+
async execute() {
|
|
86
|
+
try {
|
|
87
|
+
// do work
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (this.continueOnFail()) {
|
|
90
|
+
return [[]];
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
return [[]];
|
|
95
|
+
}
|
|
96
|
+
}`,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
invalid: [
|
|
100
|
+
{
|
|
101
|
+
name: 'node with execute but no continueOnFail',
|
|
102
|
+
code: createNodeWithExecute(`
|
|
103
|
+
const items = this.getInputData();
|
|
104
|
+
const returnData: INodeExecutionData[] = [];
|
|
105
|
+
for (let i = 0; i < items.length; i++) {
|
|
106
|
+
returnData.push({ json: { result: true } });
|
|
107
|
+
}
|
|
108
|
+
return [returnData];
|
|
109
|
+
`),
|
|
110
|
+
errors: [{ messageId: 'missingContinueOnFail' }],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'node with try/catch but no continueOnFail check',
|
|
114
|
+
code: createNodeWithExecute(`
|
|
115
|
+
const items = this.getInputData();
|
|
116
|
+
const returnData: INodeExecutionData[] = [];
|
|
117
|
+
for (let i = 0; i < items.length; i++) {
|
|
118
|
+
try {
|
|
119
|
+
returnData.push({ json: { result: true } });
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return [returnData];
|
|
125
|
+
`),
|
|
126
|
+
errors: [{ messageId: 'missingContinueOnFail' }],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
import { isNodeTypeClass } from '../utils/index.js';
|
|
4
|
+
import { createRule } from '../utils/rule-creator.js';
|
|
5
|
+
|
|
6
|
+
/** Keys that are not child AST nodes (back-references, metadata). */
|
|
7
|
+
const NON_CHILD_KEYS = new Set(['parent', 'loc', 'range', 'start', 'end', 'tokens', 'comments']);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Recursively checks whether any descendant of the given AST node is a
|
|
11
|
+
* `this.continueOnFail()` call expression.
|
|
12
|
+
*/
|
|
13
|
+
function containsContinueOnFailCall(node: TSESTree.Node): boolean {
|
|
14
|
+
if (
|
|
15
|
+
node.type === AST_NODE_TYPES.CallExpression &&
|
|
16
|
+
node.callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
17
|
+
node.callee.object.type === AST_NODE_TYPES.ThisExpression &&
|
|
18
|
+
node.callee.property.type === AST_NODE_TYPES.Identifier &&
|
|
19
|
+
node.callee.property.name === 'continueOnFail'
|
|
20
|
+
) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for (const key of Object.keys(node)) {
|
|
25
|
+
if (NON_CHILD_KEYS.has(key)) continue;
|
|
26
|
+
|
|
27
|
+
const value = (node as unknown as Record<string, unknown>)[key];
|
|
28
|
+
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
for (const child of value) {
|
|
31
|
+
if (child && typeof child === 'object' && 'type' in child) {
|
|
32
|
+
if (containsContinueOnFailCall(child as TSESTree.Node)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} else if (value && typeof value === 'object' && 'type' in value) {
|
|
38
|
+
if (containsContinueOnFailCall(value as TSESTree.Node)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const RequireContinueOnFailRule = createRule({
|
|
48
|
+
name: 'require-continue-on-fail',
|
|
49
|
+
meta: {
|
|
50
|
+
type: 'problem',
|
|
51
|
+
docs: {
|
|
52
|
+
description: 'Require continueOnFail() handling in execute() methods of node classes',
|
|
53
|
+
},
|
|
54
|
+
messages: {
|
|
55
|
+
missingContinueOnFail:
|
|
56
|
+
'execute() method must handle this.continueOnFail() for proper error handling. ' +
|
|
57
|
+
'Wrap item processing in a try/catch and check this.continueOnFail() in the catch block.',
|
|
58
|
+
},
|
|
59
|
+
schema: [],
|
|
60
|
+
},
|
|
61
|
+
defaultOptions: [],
|
|
62
|
+
create(context) {
|
|
63
|
+
return {
|
|
64
|
+
ClassDeclaration(node) {
|
|
65
|
+
if (!isNodeTypeClass(node)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const member of node.body.body) {
|
|
70
|
+
if (
|
|
71
|
+
member.type !== AST_NODE_TYPES.MethodDefinition ||
|
|
72
|
+
member.key.type !== AST_NODE_TYPES.Identifier ||
|
|
73
|
+
member.key.name !== 'execute'
|
|
74
|
+
) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (member.value.body && !containsContinueOnFailCall(member.value.body)) {
|
|
79
|
+
context.report({
|
|
80
|
+
node: member.key,
|
|
81
|
+
messageId: 'missingContinueOnFail',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
|
|
3
|
+
import { RequireNodeDescriptionFieldsRule } from './require-node-description-fields.js';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester();
|
|
6
|
+
|
|
7
|
+
const nodeFilePath = '/tmp/TestNode.node.ts';
|
|
8
|
+
const nonNodeFilePath = '/tmp/SomeHelper.ts';
|
|
9
|
+
|
|
10
|
+
function createFullNode(): string {
|
|
11
|
+
return `
|
|
12
|
+
import type { INodeType } from 'n8n-workflow';
|
|
13
|
+
|
|
14
|
+
export class TestNode implements INodeType {
|
|
15
|
+
description = {
|
|
16
|
+
displayName: 'Test Node',
|
|
17
|
+
name: 'testNode',
|
|
18
|
+
icon: 'file:testNode.svg',
|
|
19
|
+
group: ['transform'],
|
|
20
|
+
version: 1,
|
|
21
|
+
description: 'Test node description',
|
|
22
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
23
|
+
inputs: ['main'],
|
|
24
|
+
outputs: ['main'],
|
|
25
|
+
properties: [],
|
|
26
|
+
};
|
|
27
|
+
}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createNodeMissingSubtitle(): string {
|
|
31
|
+
return `
|
|
32
|
+
import type { INodeType } from 'n8n-workflow';
|
|
33
|
+
|
|
34
|
+
export class TestNode implements INodeType {
|
|
35
|
+
description = {
|
|
36
|
+
displayName: 'Test Node',
|
|
37
|
+
name: 'testNode',
|
|
38
|
+
icon: 'file:testNode.svg',
|
|
39
|
+
group: ['transform'],
|
|
40
|
+
version: 1,
|
|
41
|
+
description: 'Test node description',
|
|
42
|
+
inputs: ['main'],
|
|
43
|
+
outputs: ['main'],
|
|
44
|
+
properties: [],
|
|
45
|
+
};
|
|
46
|
+
}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createNodeMissingIconAndSubtitle(): string {
|
|
50
|
+
return `
|
|
51
|
+
import type { INodeType } from 'n8n-workflow';
|
|
52
|
+
|
|
53
|
+
export class TestNode implements INodeType {
|
|
54
|
+
description = {
|
|
55
|
+
displayName: 'Test Node',
|
|
56
|
+
name: 'testNode',
|
|
57
|
+
group: ['transform'],
|
|
58
|
+
version: 1,
|
|
59
|
+
description: 'Test node description',
|
|
60
|
+
inputs: ['main'],
|
|
61
|
+
outputs: ['main'],
|
|
62
|
+
properties: [],
|
|
63
|
+
};
|
|
64
|
+
}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createNodeExtendsBase(): string {
|
|
68
|
+
return `
|
|
69
|
+
export class TestNode extends Node {
|
|
70
|
+
description = {
|
|
71
|
+
displayName: 'Test Node',
|
|
72
|
+
name: 'testNode',
|
|
73
|
+
icon: 'file:testNode.svg',
|
|
74
|
+
group: ['transform'],
|
|
75
|
+
version: 1,
|
|
76
|
+
description: 'Test node description',
|
|
77
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
78
|
+
inputs: ['main'],
|
|
79
|
+
outputs: ['main'],
|
|
80
|
+
properties: [],
|
|
81
|
+
};
|
|
82
|
+
}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createNodeExtendsBaseMissingSubtitle(): string {
|
|
86
|
+
return `
|
|
87
|
+
export class TestNode extends Node {
|
|
88
|
+
description = {
|
|
89
|
+
displayName: 'Test Node',
|
|
90
|
+
name: 'testNode',
|
|
91
|
+
icon: 'file:testNode.svg',
|
|
92
|
+
group: ['transform'],
|
|
93
|
+
version: 1,
|
|
94
|
+
description: 'Test node description',
|
|
95
|
+
inputs: ['main'],
|
|
96
|
+
outputs: ['main'],
|
|
97
|
+
properties: [],
|
|
98
|
+
};
|
|
99
|
+
}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function createNodeWithOnlyIconAndSubtitle(): string {
|
|
103
|
+
return `
|
|
104
|
+
import type { INodeType } from 'n8n-workflow';
|
|
105
|
+
|
|
106
|
+
export class TestNode implements INodeType {
|
|
107
|
+
description = {
|
|
108
|
+
icon: 'file:testNode.svg',
|
|
109
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
110
|
+
};
|
|
111
|
+
}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function createRegularClass(): string {
|
|
115
|
+
return `
|
|
116
|
+
export class RegularClass {
|
|
117
|
+
description = {
|
|
118
|
+
displayName: 'Test',
|
|
119
|
+
};
|
|
120
|
+
}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
ruleTester.run('require-node-description-fields', RequireNodeDescriptionFieldsRule, {
|
|
124
|
+
valid: [
|
|
125
|
+
{
|
|
126
|
+
name: 'node with all required fields',
|
|
127
|
+
filename: nodeFilePath,
|
|
128
|
+
code: createFullNode(),
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'class extending Node with all required fields',
|
|
132
|
+
filename: nodeFilePath,
|
|
133
|
+
code: createNodeExtendsBase(),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'node with only icon and subtitle passes (other fields enforced by tsc)',
|
|
137
|
+
filename: nodeFilePath,
|
|
138
|
+
code: createNodeWithOnlyIconAndSubtitle(),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'class not implementing INodeType is ignored',
|
|
142
|
+
filename: nodeFilePath,
|
|
143
|
+
code: createRegularClass(),
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'non-.node.ts file is ignored',
|
|
147
|
+
filename: nonNodeFilePath,
|
|
148
|
+
code: createNodeMissingSubtitle(),
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
invalid: [
|
|
152
|
+
{
|
|
153
|
+
name: 'node missing subtitle',
|
|
154
|
+
filename: nodeFilePath,
|
|
155
|
+
code: createNodeMissingSubtitle(),
|
|
156
|
+
errors: [{ messageId: 'missingField', data: { field: 'subtitle' } }],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'node missing icon and subtitle',
|
|
160
|
+
filename: nodeFilePath,
|
|
161
|
+
code: createNodeMissingIconAndSubtitle(),
|
|
162
|
+
errors: [{ messageId: 'missingFields', data: { fields: '`icon`, `subtitle`' } }],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'class extending Node missing subtitle',
|
|
166
|
+
filename: nodeFilePath,
|
|
167
|
+
code: createNodeExtendsBaseMissingSubtitle(),
|
|
168
|
+
errors: [{ messageId: 'missingField', data: { field: 'subtitle' } }],
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
isNodeTypeClass,
|
|
5
|
+
findClassProperty,
|
|
6
|
+
findObjectProperty,
|
|
7
|
+
isFileType,
|
|
8
|
+
createRule,
|
|
9
|
+
} from '../utils/index.js';
|
|
10
|
+
|
|
11
|
+
// Fields that are optional in the TypeScript interface but required by
|
|
12
|
+
// community node review standards. TypeScript-required fields (displayName,
|
|
13
|
+
// name, group, version, description, etc.) are already caught by tsc.
|
|
14
|
+
const REQUIRED_FIELDS = ['icon', 'subtitle'] as const;
|
|
15
|
+
|
|
16
|
+
type RequiredField = (typeof REQUIRED_FIELDS)[number];
|
|
17
|
+
|
|
18
|
+
export const RequireNodeDescriptionFieldsRule = createRule({
|
|
19
|
+
name: 'require-node-description-fields',
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'problem',
|
|
22
|
+
docs: {
|
|
23
|
+
description: `Node class description must define all required fields: ${REQUIRED_FIELDS.join(', ')}`,
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
missingField: 'Node class description is missing required `{{field}}` property',
|
|
27
|
+
missingFields: 'Node class description is missing required properties: {{fields}}',
|
|
28
|
+
},
|
|
29
|
+
schema: [],
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
if (!isFileType(context.filename, '.node.ts')) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
ClassDeclaration(node) {
|
|
39
|
+
if (!isNodeTypeClass(node)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const descriptionProperty = findClassProperty(node, 'description');
|
|
44
|
+
if (
|
|
45
|
+
!descriptionProperty?.value ||
|
|
46
|
+
descriptionProperty.value.type !== TSESTree.AST_NODE_TYPES.ObjectExpression
|
|
47
|
+
) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const descriptionValue = descriptionProperty.value;
|
|
52
|
+
|
|
53
|
+
const missingFields: RequiredField[] = REQUIRED_FIELDS.filter(
|
|
54
|
+
(field) => !findObjectProperty(descriptionValue, field),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (missingFields.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (missingFields.length === 1) {
|
|
62
|
+
context.report({
|
|
63
|
+
node: descriptionProperty,
|
|
64
|
+
messageId: 'missingField',
|
|
65
|
+
data: { field: missingFields[0] },
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
context.report({
|
|
69
|
+
node: descriptionProperty,
|
|
70
|
+
messageId: 'missingFields',
|
|
71
|
+
data: { fields: missingFields.map((f) => `\`${f}\``).join(', ') },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
});
|