Skip to content

Commit f225ffa

Browse files
Merge pull request #11 from andrewjschuang/fix-default-interface-props
Fix default interface props
2 parents 8137396 + 155ff8a commit f225ffa

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ function isObjectWithProperties(node) {
2020
return true;
2121
}
2222

23+
// Default interface props don't need labels and descriptions
24+
function isDefaultInterfaceProperty(propertyName, properties) {
25+
if (propertyName === "label" || propertyName === "description") {
26+
const interfacePropValue = findPropertyWithName("type", properties)?.value;
27+
return (interfacePropValue?.value === "$.interface.timer" || interfacePropValue?.value === "$.interface.http");
28+
}
29+
return false;
30+
}
31+
2332
function getComponentFromNode(node) {
2433
if (isDefaultExport(node) && isObjectWithProperties(node.declaration)) {
2534
return node.declaration;
@@ -102,6 +111,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
102111
// We don't want to lint app props or props that are defined in propDefinitions
103112
if (!isObjectWithProperties(propDef)) continue;
104113
if (astIncludesProperty("propDefinition", propDef.properties)) continue;
114+
if (isDefaultInterfaceProperty(propertyName, propDef.properties)) continue;
105115
if (!astIncludesProperty(propertyName, propDef.properties)) {
106116
context.report({
107117
node: prop,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-pipedream",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "ESLint plugin for Pipedream components: https://pipedream.com/docs/components/api/",
55
"main": "index.js",
66
"scripts": {

tests/components.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ module.exports = {
7171
},
7272
},
7373
},
74+
missingPropsLabelTimer: {
75+
key: "test",
76+
name: "Test",
77+
description: "hello",
78+
version: "0.0.1",
79+
props: {
80+
test: {
81+
type: "$.interface.timer",
82+
description: "test",
83+
},
84+
},
85+
},
86+
missingPropsLabelHttp: {
87+
key: "test",
88+
name: "Test",
89+
description: "hello",
90+
version: "0.0.1",
91+
props: {
92+
test: {
93+
type: "$.interface.http",
94+
description: "test",
95+
},
96+
},
97+
},
7498
missingPropsDescription: {
7599
key: "test",
76100
name: "Test",
@@ -83,6 +107,30 @@ module.exports = {
83107
},
84108
},
85109
},
110+
missingPropsDescriptionTimer: {
111+
key: "test",
112+
name: "Test",
113+
description: "hello",
114+
version: "0.0.1",
115+
props: {
116+
test: {
117+
type: "$.interface.timer",
118+
label: "Test",
119+
},
120+
},
121+
},
122+
missingPropsDescriptionHttp: {
123+
key: "test",
124+
name: "Test",
125+
description: "hello",
126+
version: "0.0.1",
127+
props: {
128+
test: {
129+
type: "$.interface.http",
130+
label: "Test",
131+
},
132+
},
133+
},
86134
badSourceName: {
87135
key: "test",
88136
name: "Test",

tests/rules.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const {
99
requiredPropertyTypeMissing,
1010
optionalPropWithoutDefaultValue,
1111
missingPropsLabel,
12+
missingPropsLabelTimer,
13+
missingPropsLabelHttp,
1214
missingPropsDescription,
15+
missingPropsDescriptionTimer,
16+
missingPropsDescriptionHttp,
1317
badSourceName,
1418
badSourceDescription,
1519
tsVersion,
@@ -87,11 +91,25 @@ const componentTestConfigs = [
8791
},
8892
{
8993
ruleName: "props-label",
94+
validComponent: missingPropsLabelTimer,
95+
invalidComponent: missingPropsLabel,
96+
errorMessage: "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props",
97+
},
98+
{
99+
ruleName: "props-label",
100+
validComponent: missingPropsLabelHttp,
90101
invalidComponent: missingPropsLabel,
91102
errorMessage: "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props",
92103
},
93104
{
94105
ruleName: "props-description",
106+
validComponent: missingPropsDescriptionTimer,
107+
invalidComponent: missingPropsDescription,
108+
errorMessage: "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props",
109+
},
110+
{
111+
ruleName: "props-description",
112+
validComponent: missingPropsDescriptionHttp,
95113
invalidComponent: missingPropsDescription,
96114
errorMessage: "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props",
97115
},
@@ -184,4 +202,3 @@ RuleTester.describe("On ESM export default with preceding statements", () => {
184202
});
185203
});
186204
});
187-

0 commit comments

Comments
 (0)