Skip to content

Commit 26bd0eb

Browse files
authored
fix: exclude 'dir' props from label and description requirements (#13)
- Stop requiring `label` and `description` properties for 'dir' props - Refactor label/description exemption logic for props - Add test cases for 'dir' type props in component tests
1 parent 3fa0524 commit 26bd0eb

File tree

5 files changed

+59
-31
lines changed

5 files changed

+59
-31
lines changed

index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ 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;
23+
// Check if a prop type is exempt from label/description requirements
24+
function isExemptFromLabelDescriptionRequirement(propertyName, properties) {
25+
if (propertyName !== "label" && propertyName !== "description") return false;
26+
const typePropValue = findPropertyWithName("type", properties)?.value;
27+
if (!typePropValue?.value) return false;
28+
// Default interface props don't need labels and descriptions
29+
const isDefaultInterface = typePropValue.value === "$.interface.timer" ||
30+
typePropValue.value === "$.interface.http";
31+
// Dir props don't need labels and descriptions
32+
const isDirProp = typePropValue.value === "dir";
33+
return isDefaultInterface || isDirProp;
3034
}
3135

3236
function getComponentFromNode(node) {
@@ -111,7 +115,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
111115
// We don't want to lint app props or props that are defined in propDefinitions
112116
if (!isObjectWithProperties(propDef)) continue;
113117
if (astIncludesProperty("propDefinition", propDef.properties)) continue;
114-
if (isDefaultInterfaceProperty(propertyName, propDef.properties)) continue;
118+
if (isExemptFromLabelDescriptionRequirement(propertyName, propDef.properties)) continue;
115119
if (!astIncludesProperty(propertyName, propDef.properties)) {
116120
context.report({
117121
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": "@pipedream/eslint-plugin-pipedream",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "ESLint plugin for Pipedream components: https://pipedream.com/docs/components/api/",
55
"main": "index.js",
66
"scripts": {

tests/components.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ module.exports = {
9595
},
9696
},
9797
},
98+
missingPropsLabelDir: {
99+
key: "test",
100+
name: "Test",
101+
description: "hello",
102+
version: "0.0.1",
103+
props: {
104+
test: {
105+
type: "dir",
106+
description: "test",
107+
},
108+
},
109+
},
98110
missingPropsDescription: {
99111
key: "test",
100112
name: "Test",
@@ -131,6 +143,18 @@ module.exports = {
131143
},
132144
},
133145
},
146+
missingPropsDescriptionDir: {
147+
key: "test",
148+
name: "Test",
149+
description: "hello",
150+
version: "0.0.1",
151+
props: {
152+
test: {
153+
type: "dir",
154+
label: "Test",
155+
},
156+
},
157+
},
134158
badSourceName: {
135159
key: "test",
136160
name: "Test",

tests/rules.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ const {
1111
missingPropsLabel,
1212
missingPropsLabelTimer,
1313
missingPropsLabelHttp,
14+
missingPropsLabelDir,
1415
missingPropsDescription,
1516
missingPropsDescriptionTimer,
1617
missingPropsDescriptionHttp,
18+
missingPropsDescriptionDir,
1719
badSourceName,
1820
badSourceDescription,
1921
tsVersion,
@@ -45,14 +47,16 @@ function withPrecedingStatement(code) {
4547
function makeComponentTestCase ({
4648
ruleName,
4749
name = `${ruleName}-test`,
48-
validComponent = valid,
50+
validComponents = [
51+
valid,
52+
],
4953
invalidComponent,
5054
errorMessage,
5155
}) {
5256
return {
5357
name,
5458
ruleName,
55-
validComponent,
59+
validComponents,
5660
invalidComponent,
5761
errorMessage,
5862
};
@@ -91,25 +95,21 @@ const componentTestConfigs = [
9195
},
9296
{
9397
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,
98+
validComponents: [
99+
missingPropsLabelTimer,
100+
missingPropsLabelHttp,
101+
missingPropsLabelDir,
102+
],
101103
invalidComponent: missingPropsLabel,
102104
errorMessage: "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props",
103105
},
104106
{
105107
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,
108+
validComponents: [
109+
missingPropsDescriptionTimer,
110+
missingPropsDescriptionHttp,
111+
missingPropsDescriptionDir,
112+
],
113113
invalidComponent: missingPropsDescription,
114114
errorMessage: "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props",
115115
},
@@ -138,19 +138,19 @@ componentTestCases.forEach((testCase) => {
138138
const {
139139
name,
140140
ruleName,
141-
validComponent,
141+
validComponents,
142142
invalidComponent,
143143
errorMessage,
144144
} = testCase;
145145
ruleTester.run(name, rules[ruleName], {
146-
valid: [
146+
valid: validComponents.map((component) => ([
147147
{
148-
code: convertObjectToCJSExportString(validComponent),
148+
code: convertObjectToCJSExportString(component),
149149
},
150150
{
151-
code: convertObjectToESMExportString(validComponent),
151+
code: convertObjectToESMExportString(component),
152152
},
153-
],
153+
])).flat(),
154154
invalid: [
155155
{
156156
code: convertObjectToCJSExportString(invalidComponent),

0 commit comments

Comments
 (0)