@n8n/eslint-plugin-community-nodes 0.24.0 → 0.26.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.
Files changed (137) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/README.md +39 -52
  3. package/dist/plugin.d.ts +15 -93
  4. package/dist/plugin.d.ts.map +1 -1
  5. package/dist/plugin.js +0 -26
  6. package/dist/plugin.js.map +1 -1
  7. package/dist/rules/ai-node-package-json.d.ts +1 -1
  8. package/dist/rules/cred-class-field-icon-missing.d.ts +1 -1
  9. package/dist/rules/cred-class-oauth2-naming.d.ts +1 -1
  10. package/dist/rules/icon-validation.d.ts +1 -1
  11. package/dist/rules/index.d.ts +20 -33
  12. package/dist/rules/index.d.ts.map +1 -1
  13. package/dist/rules/index.js +0 -26
  14. package/dist/rules/index.js.map +1 -1
  15. package/dist/rules/no-credential-reuse.d.ts +1 -1
  16. package/dist/rules/no-dangerous-functions.d.ts +1 -1
  17. package/dist/rules/no-deprecated-workflow-functions.d.ts +1 -1
  18. package/dist/rules/no-restricted-imports.d.ts +1 -1
  19. package/dist/rules/no-restricted-imports.d.ts.map +1 -1
  20. package/dist/rules/no-restricted-imports.js +14 -5
  21. package/dist/rules/no-restricted-imports.js.map +1 -1
  22. package/dist/rules/node-class-description-icon-missing.d.ts +1 -1
  23. package/dist/rules/node-connection-type-literal.js.map +1 -1
  24. package/dist/rules/package-name-convention.d.ts +1 -1
  25. package/dist/rules/require-version.d.ts +1 -1
  26. package/dist/rules/trigger-node-conventions.d.ts +1 -1
  27. package/dist/rules/valid-author.d.ts +1 -1
  28. package/dist/rules/valid-credential-references.d.ts +1 -1
  29. package/dist/rules/valid-description.d.ts +1 -1
  30. package/dist/rules/valid-peer-dependencies.d.ts +1 -1
  31. package/dist/rules/webhook-lifecycle-complete.d.ts +1 -1
  32. package/dist/typecheck.tsbuildinfo +1 -1
  33. package/dist/utils/ast-utils.js.map +1 -1
  34. package/dist/utils/file-utils.d.ts +7 -0
  35. package/dist/utils/file-utils.d.ts.map +1 -1
  36. package/dist/utils/file-utils.js +28 -6
  37. package/dist/utils/file-utils.js.map +1 -1
  38. package/docs/rules/no-forbidden-lifecycle-scripts.md +1 -1
  39. package/docs/rules/no-restricted-imports.md +9 -0
  40. package/package.json +6 -5
  41. package/src/plugin.ts +0 -26
  42. package/src/rules/index.ts +0 -26
  43. package/src/rules/no-restricted-imports.test.ts +63 -0
  44. package/src/rules/no-restricted-imports.ts +17 -4
  45. package/src/utils/file-utils.ts +27 -6
  46. package/tsconfig.json +1 -1
  47. package/dist/rules/cred-class-name-field-conventions.d.ts +0 -2
  48. package/dist/rules/cred-class-name-field-conventions.d.ts.map +0 -1
  49. package/dist/rules/cred-class-name-field-conventions.js +0 -89
  50. package/dist/rules/cred-class-name-field-conventions.js.map +0 -1
  51. package/dist/rules/cred-class-name-suffix.d.ts +0 -2
  52. package/dist/rules/cred-class-name-suffix.d.ts.map +0 -1
  53. package/dist/rules/cred-class-name-suffix.js +0 -53
  54. package/dist/rules/cred-class-name-suffix.js.map +0 -1
  55. package/dist/rules/cred-filename-against-convention.d.ts +0 -2
  56. package/dist/rules/cred-filename-against-convention.d.ts.map +0 -1
  57. package/dist/rules/cred-filename-against-convention.js +0 -42
  58. package/dist/rules/cred-filename-against-convention.js.map +0 -1
  59. package/dist/rules/no-asterisk-in-option-names.d.ts +0 -2
  60. package/dist/rules/no-asterisk-in-option-names.d.ts.map +0 -1
  61. package/dist/rules/no-asterisk-in-option-names.js +0 -90
  62. package/dist/rules/no-asterisk-in-option-names.js.map +0 -1
  63. package/dist/rules/no-duplicate-param-options.d.ts +0 -2
  64. package/dist/rules/no-duplicate-param-options.d.ts.map +0 -1
  65. package/dist/rules/no-duplicate-param-options.js +0 -97
  66. package/dist/rules/no-duplicate-param-options.js.map +0 -1
  67. package/dist/rules/node-class-description-name-camelcase.d.ts +0 -2
  68. package/dist/rules/node-class-description-name-camelcase.d.ts.map +0 -1
  69. package/dist/rules/node-class-description-name-camelcase.js +0 -92
  70. package/dist/rules/node-class-description-name-camelcase.js.map +0 -1
  71. package/dist/rules/node-filename-against-convention.d.ts +0 -2
  72. package/dist/rules/node-filename-against-convention.d.ts.map +0 -1
  73. package/dist/rules/node-filename-against-convention.js +0 -61
  74. package/dist/rules/node-filename-against-convention.js.map +0 -1
  75. package/dist/rules/node-operation-error-itemindex.d.ts +0 -12
  76. package/dist/rules/node-operation-error-itemindex.d.ts.map +0 -1
  77. package/dist/rules/node-operation-error-itemindex.js +0 -184
  78. package/dist/rules/node-operation-error-itemindex.js.map +0 -1
  79. package/dist/rules/options-sorted-alphabetically.d.ts +0 -2
  80. package/dist/rules/options-sorted-alphabetically.d.ts.map +0 -1
  81. package/dist/rules/options-sorted-alphabetically.js +0 -95
  82. package/dist/rules/options-sorted-alphabetically.js.map +0 -1
  83. package/dist/rules/require-community-node-keyword.d.ts +0 -2
  84. package/dist/rules/require-community-node-keyword.d.ts.map +0 -1
  85. package/dist/rules/require-community-node-keyword.js +0 -65
  86. package/dist/rules/require-community-node-keyword.js.map +0 -1
  87. package/dist/rules/require-continue-on-fail.d.ts +0 -2
  88. package/dist/rules/require-continue-on-fail.d.ts.map +0 -1
  89. package/dist/rules/require-continue-on-fail.js +0 -76
  90. package/dist/rules/require-continue-on-fail.js.map +0 -1
  91. package/dist/rules/require-mit-license.d.ts +0 -2
  92. package/dist/rules/require-mit-license.d.ts.map +0 -1
  93. package/dist/rules/require-mit-license.js +0 -57
  94. package/dist/rules/require-mit-license.js.map +0 -1
  95. package/dist/rules/require-param-default.d.ts +0 -15
  96. package/dist/rules/require-param-default.d.ts.map +0 -1
  97. package/dist/rules/require-param-default.js +0 -75
  98. package/dist/rules/require-param-default.js.map +0 -1
  99. package/docs/rules/cred-class-name-field-conventions.md +0 -38
  100. package/docs/rules/cred-class-name-suffix.md +0 -46
  101. package/docs/rules/cred-filename-against-convention.md +0 -42
  102. package/docs/rules/no-asterisk-in-option-names.md +0 -61
  103. package/docs/rules/no-duplicate-param-options.md +0 -46
  104. package/docs/rules/node-class-description-name-camelcase.md +0 -41
  105. package/docs/rules/node-filename-against-convention.md +0 -50
  106. package/docs/rules/node-operation-error-itemindex.md +0 -81
  107. package/docs/rules/options-sorted-alphabetically.md +0 -63
  108. package/docs/rules/require-community-node-keyword.md +0 -45
  109. package/docs/rules/require-continue-on-fail.md +0 -56
  110. package/docs/rules/require-mit-license.md +0 -38
  111. package/docs/rules/require-param-default.md +0 -60
  112. package/src/rules/cred-class-name-field-conventions.test.ts +0 -121
  113. package/src/rules/cred-class-name-field-conventions.ts +0 -102
  114. package/src/rules/cred-class-name-suffix.test.ts +0 -74
  115. package/src/rules/cred-class-name-suffix.ts +0 -57
  116. package/src/rules/cred-filename-against-convention.test.ts +0 -72
  117. package/src/rules/cred-filename-against-convention.ts +0 -48
  118. package/src/rules/no-asterisk-in-option-names.test.ts +0 -185
  119. package/src/rules/no-asterisk-in-option-names.ts +0 -111
  120. package/src/rules/no-duplicate-param-options.test.ts +0 -125
  121. package/src/rules/no-duplicate-param-options.ts +0 -125
  122. package/src/rules/node-class-description-name-camelcase.test.ts +0 -121
  123. package/src/rules/node-class-description-name-camelcase.ts +0 -114
  124. package/src/rules/node-filename-against-convention.test.ts +0 -115
  125. package/src/rules/node-filename-against-convention.ts +0 -76
  126. package/src/rules/node-operation-error-itemindex.test.ts +0 -280
  127. package/src/rules/node-operation-error-itemindex.ts +0 -223
  128. package/src/rules/options-sorted-alphabetically.test.ts +0 -468
  129. package/src/rules/options-sorted-alphabetically.ts +0 -129
  130. package/src/rules/require-community-node-keyword.test.ts +0 -82
  131. package/src/rules/require-community-node-keyword.ts +0 -78
  132. package/src/rules/require-continue-on-fail.test.ts +0 -129
  133. package/src/rules/require-continue-on-fail.ts +0 -88
  134. package/src/rules/require-mit-license.test.ts +0 -67
  135. package/src/rules/require-mit-license.ts +0 -65
  136. package/src/rules/require-param-default.test.ts +0 -227
  137. package/src/rules/require-param-default.ts +0 -89
@@ -1,111 +0,0 @@
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
- findObjectProperty,
8
- getStringLiteralValue,
9
- isFileType,
10
- createRule,
11
- } from '../utils/index.js';
12
-
13
- export const NoAsteriskInOptionNamesRule = createRule({
14
- name: 'no-asterisk-in-option-names',
15
- meta: {
16
- type: 'suggestion',
17
- docs: {
18
- description: 'Disallow asterisk characters in node option name values',
19
- },
20
- hasSuggestions: true,
21
- messages: {
22
- asteriskInOptionName:
23
- 'Option name "{{ name }}" contains "*", which renders ambiguously in the n8n UI. Use bracketed notation like "[All]" instead.',
24
- replaceAsterisk: 'Replace "*" with "[All]".',
25
- },
26
- schema: [],
27
- },
28
- defaultOptions: [],
29
- create(context) {
30
- if (!isFileType(context.filename, '.node.ts')) {
31
- return {};
32
- }
33
-
34
- // Check every object that is a direct element of an `options` array.
35
- const checkOptionsArray = (optionsArray: TSESTree.ArrayExpression): void => {
36
- for (const option of optionsArray.elements) {
37
- if (!option || option.type !== AST_NODE_TYPES.ObjectExpression) {
38
- continue;
39
- }
40
-
41
- const valueNode = findObjectProperty(option, 'name')?.value;
42
- if (!valueNode) {
43
- continue;
44
- }
45
-
46
- const name = getStringLiteralValue(valueNode);
47
- if (!name?.includes('*')) {
48
- continue;
49
- }
50
-
51
- context.report({
52
- node: valueNode,
53
- messageId: 'asteriskInOptionName',
54
- data: { name },
55
- suggest: [
56
- {
57
- messageId: 'replaceAsterisk',
58
- fix(fixer) {
59
- const quote = context.sourceCode.getText(valueNode).at(0) ?? "'";
60
- return fixer.replaceText(
61
- valueNode,
62
- `${quote}${name.replaceAll('*', '[All]')}${quote}`,
63
- );
64
- },
65
- },
66
- ],
67
- });
68
- }
69
- };
70
-
71
- const traverse = (node: TSESTree.Node): void => {
72
- if (node.type === AST_NODE_TYPES.ObjectExpression) {
73
- const optionsProperty = findObjectProperty(node, 'options');
74
- if (optionsProperty?.value.type === AST_NODE_TYPES.ArrayExpression) {
75
- checkOptionsArray(optionsProperty.value);
76
- }
77
- }
78
-
79
- for (const key in node) {
80
- if (key === 'parent') {
81
- continue;
82
- }
83
- const child = node[key as keyof TSESTree.Node] as unknown;
84
- if (Array.isArray(child)) {
85
- for (const item of child) {
86
- if (item && typeof item === 'object' && 'type' in item) {
87
- traverse(item as TSESTree.Node);
88
- }
89
- }
90
- } else if (child && typeof child === 'object' && 'type' in child) {
91
- traverse(child as TSESTree.Node);
92
- }
93
- }
94
- };
95
-
96
- return {
97
- ClassDeclaration(node) {
98
- if (!isNodeTypeClass(node)) {
99
- return;
100
- }
101
-
102
- const descriptionProperty = findClassProperty(node, 'description');
103
- if (!descriptionProperty?.value) {
104
- return;
105
- }
106
-
107
- traverse(descriptionProperty.value);
108
- },
109
- };
110
- },
111
- });
@@ -1,125 +0,0 @@
1
- import { RuleTester } from '@typescript-eslint/rule-tester';
2
-
3
- import { NoDuplicateParamOptionsRule } from './no-duplicate-param-options.js';
4
-
5
- const ruleTester = new RuleTester();
6
-
7
- function nodeCode(options: string, type = 'options'): 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: 'testNode',
15
- properties: [
16
- {
17
- displayName: 'Resource',
18
- name: 'resource',
19
- type: '${type}',
20
- options: [${options}],
21
- default: '',
22
- },
23
- ],
24
- };
25
- }
26
- `;
27
- }
28
-
29
- ruleTester.run('no-duplicate-param-options', NoDuplicateParamOptionsRule, {
30
- valid: [
31
- {
32
- name: 'non-INodeType class is skipped',
33
- filename: '/tmp/TestNode.node.ts',
34
- code: 'export class Foo {}',
35
- },
36
- {
37
- name: 'unique names and values',
38
- filename: '/tmp/TestNode.node.ts',
39
- code: nodeCode(`
40
- { name: 'Create', value: 'create' },
41
- { name: 'Delete', value: 'delete' },
42
- `),
43
- },
44
- {
45
- name: 'unique numeric values',
46
- filename: '/tmp/TestNode.node.ts',
47
- code: nodeCode(`
48
- { name: 'One', value: 1 },
49
- { name: 'Two', value: 2 },
50
- `),
51
- },
52
- {
53
- name: 'multiOptions with unique options',
54
- filename: '/tmp/TestNode.node.ts',
55
- code: nodeCode(
56
- `
57
- { name: 'A', value: 'a' },
58
- { name: 'B', value: 'b' },
59
- `,
60
- 'multiOptions',
61
- ),
62
- },
63
- {
64
- name: 'non-node.ts file is skipped',
65
- filename: '/tmp/TestNode.ts',
66
- code: nodeCode(`
67
- { name: 'Dup', value: 'a' },
68
- { name: 'Dup', value: 'b' },
69
- `),
70
- },
71
- ],
72
- invalid: [
73
- {
74
- name: 'duplicate name',
75
- filename: '/tmp/TestNode.node.ts',
76
- code: nodeCode(`
77
- { name: 'Create', value: 'create' },
78
- { name: 'Create', value: 'create2' },
79
- `),
80
- errors: [{ messageId: 'duplicateName', data: { value: 'Create', displayName: 'Resource' } }],
81
- },
82
- {
83
- name: 'duplicate value',
84
- filename: '/tmp/TestNode.node.ts',
85
- code: nodeCode(`
86
- { name: 'Create', value: 'create' },
87
- { name: 'Make', value: 'create' },
88
- `),
89
- errors: [{ messageId: 'duplicateValue', data: { value: 'create', displayName: 'Resource' } }],
90
- },
91
- {
92
- name: 'duplicate numeric value',
93
- filename: '/tmp/TestNode.node.ts',
94
- code: nodeCode(`
95
- { name: 'One', value: 1 },
96
- { name: 'Uno', value: 1 },
97
- `),
98
- errors: [{ messageId: 'duplicateValue', data: { value: '1', displayName: 'Resource' } }],
99
- },
100
- {
101
- name: 'duplicate name and value reported separately',
102
- filename: '/tmp/TestNode.node.ts',
103
- code: nodeCode(`
104
- { name: 'Create', value: 'create' },
105
- { name: 'Create', value: 'create' },
106
- `),
107
- errors: [
108
- { messageId: 'duplicateName', data: { value: 'Create', displayName: 'Resource' } },
109
- { messageId: 'duplicateValue', data: { value: 'create', displayName: 'Resource' } },
110
- ],
111
- },
112
- {
113
- name: 'duplicate in multiOptions',
114
- filename: '/tmp/TestNode.node.ts',
115
- code: nodeCode(
116
- `
117
- { name: 'A', value: 'a' },
118
- { name: 'A', value: 'b' },
119
- `,
120
- 'multiOptions',
121
- ),
122
- errors: [{ messageId: 'duplicateName', data: { value: 'A', displayName: 'Resource' } }],
123
- },
124
- ],
125
- });
@@ -1,125 +0,0 @@
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
- findObjectProperty,
8
- getStringLiteralValue,
9
- getLiteralValue,
10
- isFileType,
11
- createRule,
12
- } from '../utils/index.js';
13
-
14
- export const NoDuplicateParamOptionsRule = createRule({
15
- name: 'no-duplicate-param-options',
16
- meta: {
17
- type: 'problem',
18
- docs: {
19
- description: 'Disallow duplicate option names or values within a single node parameter',
20
- },
21
- messages: {
22
- duplicateName: 'Duplicate option name "{{ value }}" in parameter "{{ displayName }}".',
23
- duplicateValue: 'Duplicate option value "{{ value }}" in parameter "{{ displayName }}".',
24
- },
25
- schema: [],
26
- },
27
- defaultOptions: [],
28
- create(context) {
29
- if (!isFileType(context.filename, '.node.ts')) {
30
- return {};
31
- }
32
-
33
- const checkProperty = (property: TSESTree.ObjectExpression): void => {
34
- const typeProperty = findObjectProperty(property, 'type');
35
- const type = typeProperty ? getStringLiteralValue(typeProperty.value) : null;
36
- if (type !== 'options' && type !== 'multiOptions') {
37
- return;
38
- }
39
-
40
- const optionsProperty = findObjectProperty(property, 'options');
41
- if (
42
- !optionsProperty?.value ||
43
- optionsProperty.value.type !== AST_NODE_TYPES.ArrayExpression
44
- ) {
45
- return;
46
- }
47
-
48
- const displayNameProperty = findObjectProperty(property, 'displayName');
49
- const displayName =
50
- (displayNameProperty ? getStringLiteralValue(displayNameProperty.value) : null) ??
51
- 'unknown';
52
-
53
- const seenNames = new Set<string>();
54
- const seenValues = new Set<string | number | boolean>();
55
-
56
- for (const option of optionsProperty.value.elements) {
57
- if (!option || option.type !== AST_NODE_TYPES.ObjectExpression) {
58
- continue;
59
- }
60
-
61
- const nameProperty = findObjectProperty(option, 'name');
62
- const name = nameProperty ? getStringLiteralValue(nameProperty.value) : null;
63
- if (name !== null) {
64
- if (seenNames.has(name)) {
65
- context.report({
66
- node: nameProperty!.value,
67
- messageId: 'duplicateName',
68
- data: { value: name, displayName },
69
- });
70
- }
71
- seenNames.add(name);
72
- }
73
-
74
- const valueProperty = findObjectProperty(option, 'value');
75
- const value = valueProperty ? getLiteralValue(valueProperty.value) : null;
76
- if (value !== null) {
77
- if (seenValues.has(value)) {
78
- context.report({
79
- node: valueProperty!.value,
80
- messageId: 'duplicateValue',
81
- data: { value: String(value), displayName },
82
- });
83
- }
84
- seenValues.add(value);
85
- }
86
- }
87
- };
88
-
89
- const analyzeNodeDescription = (descriptionValue: TSESTree.Expression | null): void => {
90
- if (!descriptionValue || descriptionValue.type !== AST_NODE_TYPES.ObjectExpression) {
91
- return;
92
- }
93
-
94
- const propertiesProperty = findObjectProperty(descriptionValue, 'properties');
95
- if (
96
- !propertiesProperty?.value ||
97
- propertiesProperty.value.type !== AST_NODE_TYPES.ArrayExpression
98
- ) {
99
- return;
100
- }
101
-
102
- for (const property of propertiesProperty.value.elements) {
103
- if (!property || property.type !== AST_NODE_TYPES.ObjectExpression) {
104
- continue;
105
- }
106
- checkProperty(property);
107
- }
108
- };
109
-
110
- return {
111
- ClassDeclaration(node) {
112
- if (!isNodeTypeClass(node)) {
113
- return;
114
- }
115
-
116
- const descriptionProperty = findClassProperty(node, 'description');
117
- if (!descriptionProperty) {
118
- return;
119
- }
120
-
121
- analyzeNodeDescription(descriptionProperty.value);
122
- },
123
- };
124
- },
125
- });
@@ -1,121 +0,0 @@
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
- });
@@ -1,114 +0,0 @@
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
- });
@@ -1,115 +0,0 @@
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
- });