@n8n/eslint-plugin-community-nodes 0.22.0 → 0.24.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 +4 -0
- package/README.md +5 -0
- package/dist/plugin.d.ts +30 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +10 -0
- 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/no-asterisk-in-option-names.d.ts +2 -0
- package/dist/rules/no-asterisk-in-option-names.d.ts.map +1 -0
- package/dist/rules/no-asterisk-in-option-names.js +90 -0
- package/dist/rules/no-asterisk-in-option-names.js.map +1 -0
- package/dist/rules/no-duplicate-param-options.d.ts +2 -0
- package/dist/rules/no-duplicate-param-options.d.ts.map +1 -0
- package/dist/rules/no-duplicate-param-options.js +97 -0
- package/dist/rules/no-duplicate-param-options.js.map +1 -0
- package/dist/rules/require-mit-license.d.ts +2 -0
- package/dist/rules/require-mit-license.d.ts.map +1 -0
- package/dist/rules/require-mit-license.js +57 -0
- package/dist/rules/require-mit-license.js.map +1 -0
- package/dist/rules/require-param-default.d.ts +15 -0
- package/dist/rules/require-param-default.d.ts.map +1 -0
- package/dist/rules/require-param-default.js +75 -0
- package/dist/rules/require-param-default.js.map +1 -0
- package/dist/rules/trigger-node-conventions.d.ts +2 -0
- package/dist/rules/trigger-node-conventions.d.ts.map +1 -0
- package/dist/rules/trigger-node-conventions.js +70 -0
- package/dist/rules/trigger-node-conventions.js.map +1 -0
- package/dist/typecheck.tsbuildinfo +1 -1
- package/docs/rules/no-asterisk-in-option-names.md +61 -0
- package/docs/rules/no-duplicate-param-options.md +46 -0
- package/docs/rules/require-mit-license.md +38 -0
- package/docs/rules/require-param-default.md +60 -0
- package/docs/rules/trigger-node-conventions.md +49 -0
- package/package.json +6 -5
- package/src/plugin.ts +10 -0
- package/src/rules/index.ts +10 -0
- package/src/rules/no-asterisk-in-option-names.test.ts +185 -0
- package/src/rules/no-asterisk-in-option-names.ts +111 -0
- package/src/rules/no-duplicate-param-options.test.ts +125 -0
- package/src/rules/no-duplicate-param-options.ts +125 -0
- package/src/rules/no-forbidden-lifecycle-scripts.test.ts +2 -2
- package/src/rules/require-mit-license.test.ts +67 -0
- package/src/rules/require-mit-license.ts +65 -0
- package/src/rules/require-param-default.test.ts +227 -0
- package/src/rules/require-param-default.ts +89 -0
- package/src/rules/trigger-node-conventions.test.ts +110 -0
- package/src/rules/trigger-node-conventions.ts +92 -0
- package/.turbo/turbo-build$colon$unchecked.log +0 -4
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requires every node parameter to declare a `default` property.
|
|
3
|
+
*
|
|
4
|
+
* A parameter is detected structurally: an object literal inside a node's
|
|
5
|
+
* `description` with `displayName`, `name`, and `type` all set to string
|
|
6
|
+
* literals — the shape every `INodeProperties` entry has. This avoids
|
|
7
|
+
* hardcoding the `NodePropertyTypes` union (which would silently go stale as
|
|
8
|
+
* new types are added) and naturally excludes `options`-array entries, which
|
|
9
|
+
* carry `name`/`value` but no `displayName`/`type`.
|
|
10
|
+
*
|
|
11
|
+
* Without a `default`, n8n cannot reliably initialise the parameter's value,
|
|
12
|
+
* which leads to inconsistent runtime behaviour in the editor and on execution.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { simpleTraverse } from '@typescript-eslint/typescript-estree';
|
|
16
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
17
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
createRule,
|
|
21
|
+
findClassProperty,
|
|
22
|
+
findObjectProperty,
|
|
23
|
+
getStringLiteralValue,
|
|
24
|
+
isFileType,
|
|
25
|
+
isNodeTypeClass,
|
|
26
|
+
} from '../utils/index.js';
|
|
27
|
+
|
|
28
|
+
/** Property keys an `INodeProperties` parameter always carries as string literals. */
|
|
29
|
+
const REQUIRED_PARAM_KEYS = ['displayName', 'name', 'type'] as const;
|
|
30
|
+
|
|
31
|
+
/** Returns true when the object literal has the shape of a node parameter. */
|
|
32
|
+
function isNodeParameter(node: TSESTree.ObjectExpression): boolean {
|
|
33
|
+
return REQUIRED_PARAM_KEYS.every((key) => {
|
|
34
|
+
const property = findObjectProperty(node, key);
|
|
35
|
+
return property !== null && getStringLiteralValue(property.value) !== null;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const RequireParamDefaultRule = createRule({
|
|
40
|
+
name: 'require-param-default',
|
|
41
|
+
meta: {
|
|
42
|
+
type: 'problem',
|
|
43
|
+
docs: {
|
|
44
|
+
description: 'Require every node parameter to declare a default value.',
|
|
45
|
+
},
|
|
46
|
+
messages: {
|
|
47
|
+
missingDefault:
|
|
48
|
+
"Node parameter '{{ name }}' is missing a `default` value. Add a `default` property so the parameter initialises consistently.",
|
|
49
|
+
},
|
|
50
|
+
schema: [],
|
|
51
|
+
},
|
|
52
|
+
defaultOptions: [],
|
|
53
|
+
create(context) {
|
|
54
|
+
if (!isFileType(context.filename, '.node.ts')) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const reportIfMissingDefault = (node: TSESTree.ObjectExpression): void => {
|
|
59
|
+
if (!isNodeParameter(node) || findObjectProperty(node, 'default') !== null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const nameProperty = findObjectProperty(node, 'name');
|
|
63
|
+
context.report({
|
|
64
|
+
node,
|
|
65
|
+
messageId: 'missingDefault',
|
|
66
|
+
data: { name: getStringLiteralValue(nameProperty?.value ?? null) ?? '' },
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
// Scope to an INodeType class's `description`, then walk only that
|
|
72
|
+
// subtree, so helper classes and object literals elsewhere in the file
|
|
73
|
+
// (e.g. in method bodies) that share the parameter shape are ignored.
|
|
74
|
+
ClassDeclaration(node) {
|
|
75
|
+
if (!isNodeTypeClass(node)) return;
|
|
76
|
+
const description = findClassProperty(node, 'description');
|
|
77
|
+
if (description?.value?.type !== AST_NODE_TYPES.ObjectExpression) return;
|
|
78
|
+
|
|
79
|
+
simpleTraverse(description.value, {
|
|
80
|
+
enter(child) {
|
|
81
|
+
if (child.type === AST_NODE_TYPES.ObjectExpression) {
|
|
82
|
+
reportIfMissingDefault(child);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
|
|
3
|
+
import { TriggerNodeConventionsRule } from './trigger-node-conventions.js';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester();
|
|
6
|
+
|
|
7
|
+
function createNodeCode(options: {
|
|
8
|
+
className: string;
|
|
9
|
+
name: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
inputs: string;
|
|
12
|
+
}): string {
|
|
13
|
+
const { className, name, displayName, inputs } = options;
|
|
14
|
+
return `
|
|
15
|
+
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
16
|
+
|
|
17
|
+
export class ${className} implements INodeType {
|
|
18
|
+
description: INodeTypeDescription = {
|
|
19
|
+
displayName: '${displayName}',
|
|
20
|
+
name: '${name}',
|
|
21
|
+
group: ['trigger'],
|
|
22
|
+
version: 1,
|
|
23
|
+
description: 'A test node',
|
|
24
|
+
defaults: { name: '${displayName}' },
|
|
25
|
+
inputs: ${inputs},
|
|
26
|
+
outputs: ['main'],
|
|
27
|
+
properties: [],
|
|
28
|
+
};
|
|
29
|
+
}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ruleTester.run('trigger-node-conventions', TriggerNodeConventionsRule, {
|
|
33
|
+
valid: [
|
|
34
|
+
{
|
|
35
|
+
name: 'class that does not implement INodeType',
|
|
36
|
+
filename: 'MyTrigger.node.ts',
|
|
37
|
+
code: 'export class MyTrigger {}',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'non-trigger node class is ignored',
|
|
41
|
+
filename: 'My.node.ts',
|
|
42
|
+
code: createNodeCode({
|
|
43
|
+
className: 'My',
|
|
44
|
+
name: 'my',
|
|
45
|
+
displayName: 'My Node',
|
|
46
|
+
inputs: "['main']",
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'compliant trigger node',
|
|
51
|
+
filename: 'MyTrigger.node.ts',
|
|
52
|
+
code: createNodeCode({
|
|
53
|
+
className: 'MyTrigger',
|
|
54
|
+
name: 'myTrigger',
|
|
55
|
+
displayName: 'My Trigger',
|
|
56
|
+
inputs: '[]',
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
invalid: [
|
|
61
|
+
{
|
|
62
|
+
name: 'name missing Trigger suffix',
|
|
63
|
+
filename: 'MyTrigger.node.ts',
|
|
64
|
+
code: createNodeCode({
|
|
65
|
+
className: 'MyTrigger',
|
|
66
|
+
name: 'my',
|
|
67
|
+
displayName: 'My Trigger',
|
|
68
|
+
inputs: '[]',
|
|
69
|
+
}),
|
|
70
|
+
errors: [{ messageId: 'nameMissingSuffix', data: { value: 'my' } }],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'displayName missing Trigger',
|
|
74
|
+
filename: 'MyTrigger.node.ts',
|
|
75
|
+
code: createNodeCode({
|
|
76
|
+
className: 'MyTrigger',
|
|
77
|
+
name: 'myTrigger',
|
|
78
|
+
displayName: 'My Node',
|
|
79
|
+
inputs: '[]',
|
|
80
|
+
}),
|
|
81
|
+
errors: [{ messageId: 'displayNameMissingTrigger', data: { value: 'My Node' } }],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'inputs is not empty',
|
|
85
|
+
filename: 'MyTrigger.node.ts',
|
|
86
|
+
code: createNodeCode({
|
|
87
|
+
className: 'MyTrigger',
|
|
88
|
+
name: 'myTrigger',
|
|
89
|
+
displayName: 'My Trigger',
|
|
90
|
+
inputs: "['main']",
|
|
91
|
+
}),
|
|
92
|
+
errors: [{ messageId: 'inputsNotEmpty' }],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'all three violations at once',
|
|
96
|
+
filename: 'MyTrigger.node.ts',
|
|
97
|
+
code: createNodeCode({
|
|
98
|
+
className: 'MyTrigger',
|
|
99
|
+
name: 'my',
|
|
100
|
+
displayName: 'My Node',
|
|
101
|
+
inputs: "['main']",
|
|
102
|
+
}),
|
|
103
|
+
errors: [
|
|
104
|
+
{ messageId: 'displayNameMissingTrigger' },
|
|
105
|
+
{ messageId: 'nameMissingSuffix' },
|
|
106
|
+
{ messageId: 'inputsNotEmpty' },
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
export const TriggerNodeConventionsRule = createRule({
|
|
13
|
+
name: 'trigger-node-conventions',
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'problem',
|
|
16
|
+
docs: {
|
|
17
|
+
description:
|
|
18
|
+
'Trigger nodes (class name ends with `Trigger`) must label themselves consistently as triggers',
|
|
19
|
+
},
|
|
20
|
+
messages: {
|
|
21
|
+
nameMissingSuffix: "Trigger node `description.name` '{{value}}' must end with 'Trigger'",
|
|
22
|
+
displayNameMissingTrigger:
|
|
23
|
+
"Trigger node `description.displayName` '{{value}}' must contain 'Trigger'",
|
|
24
|
+
inputsNotEmpty: 'Trigger node `description.inputs` must be an empty array `[]`',
|
|
25
|
+
},
|
|
26
|
+
schema: [],
|
|
27
|
+
},
|
|
28
|
+
defaultOptions: [],
|
|
29
|
+
create(context) {
|
|
30
|
+
if (!isFileType(context.filename, '.node.ts')) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
ClassDeclaration(node) {
|
|
36
|
+
if (!isNodeTypeClass(node)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!node.id?.name.endsWith('Trigger')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const descriptionProperty = findClassProperty(node, 'description');
|
|
45
|
+
if (descriptionProperty?.value?.type !== TSESTree.AST_NODE_TYPES.ObjectExpression) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const description = descriptionProperty.value;
|
|
49
|
+
|
|
50
|
+
const displayNameProperty = findObjectProperty(description, 'displayName');
|
|
51
|
+
const displayNameValue = displayNameProperty
|
|
52
|
+
? getStringLiteralValue(displayNameProperty.value)
|
|
53
|
+
: null;
|
|
54
|
+
if (
|
|
55
|
+
displayNameProperty &&
|
|
56
|
+
displayNameValue !== null &&
|
|
57
|
+
!displayNameValue.includes('Trigger')
|
|
58
|
+
) {
|
|
59
|
+
context.report({
|
|
60
|
+
node: displayNameProperty.value,
|
|
61
|
+
messageId: 'displayNameMissingTrigger',
|
|
62
|
+
data: { value: displayNameValue },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const nameProperty = findObjectProperty(description, 'name');
|
|
67
|
+
const nameValue = nameProperty ? getStringLiteralValue(nameProperty.value) : null;
|
|
68
|
+
if (nameProperty && nameValue !== null && !nameValue.endsWith('Trigger')) {
|
|
69
|
+
context.report({
|
|
70
|
+
node: nameProperty.value,
|
|
71
|
+
messageId: 'nameMissingSuffix',
|
|
72
|
+
data: { value: nameValue },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const inputsProperty = findObjectProperty(description, 'inputs');
|
|
77
|
+
if (
|
|
78
|
+
inputsProperty &&
|
|
79
|
+
!(
|
|
80
|
+
inputsProperty.value.type === TSESTree.AST_NODE_TYPES.ArrayExpression &&
|
|
81
|
+
inputsProperty.value.elements.length === 0
|
|
82
|
+
)
|
|
83
|
+
) {
|
|
84
|
+
context.report({
|
|
85
|
+
node: inputsProperty.value,
|
|
86
|
+
messageId: 'inputsNotEmpty',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
});
|