Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ function isObjectWithProperties(node) {
return true;
}

// Default interface props don't need labels and descriptions
function isDefaultInterfaceProperty(propertyName, properties) {
if (propertyName === "label" || propertyName === "description") {
const interfacePropValue = findPropertyWithName("type", properties)?.value;
return (interfacePropValue?.value === "$.interface.timer" || interfacePropValue?.value === "$.interface.http");
}
return false;
// Check if a prop type is exempt from label/description requirements
function isExemptFromLabelDescriptionRequirement(propertyName, properties) {
if (propertyName !== "label" && propertyName !== "description") return false;
const typePropValue = findPropertyWithName("type", properties)?.value;
if (!typePropValue?.value) return false;
// Default interface props don't need labels and descriptions
const isDefaultInterface = typePropValue.value === "$.interface.timer" ||
typePropValue.value === "$.interface.http";
// Dir props don't need labels and descriptions
const isDirProp = typePropValue.value === "dir";
return isDefaultInterface || isDirProp;
}

function getComponentFromNode(node) {
Expand Down Expand Up @@ -111,7 +115,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
// We don't want to lint app props or props that are defined in propDefinitions
if (!isObjectWithProperties(propDef)) continue;
if (astIncludesProperty("propDefinition", propDef.properties)) continue;
if (isDefaultInterfaceProperty(propertyName, propDef.properties)) continue;
if (isExemptFromLabelDescriptionRequirement(propertyName, propDef.properties)) continue;
if (!astIncludesProperty(propertyName, propDef.properties)) {
context.report({
node: prop,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/eslint-plugin-pipedream",
"version": "0.2.4",
"version": "0.2.5",
"description": "ESLint plugin for Pipedream components: https://pipedream.com/docs/components/api/",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 24 additions & 0 deletions tests/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ module.exports = {
},
},
},
missingPropsLabelDir: {
key: "test",
name: "Test",
description: "hello",
version: "0.0.1",
props: {
test: {
type: "dir",
description: "test",
},
},
},
missingPropsDescription: {
key: "test",
name: "Test",
Expand Down Expand Up @@ -131,6 +143,18 @@ module.exports = {
},
},
},
missingPropsDescriptionDir: {
key: "test",
name: "Test",
description: "hello",
version: "0.0.1",
props: {
test: {
type: "dir",
label: "Test",
},
},
},
badSourceName: {
key: "test",
name: "Test",
Expand Down
42 changes: 21 additions & 21 deletions tests/rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const {
missingPropsLabel,
missingPropsLabelTimer,
missingPropsLabelHttp,
missingPropsLabelDir,
missingPropsDescription,
missingPropsDescriptionTimer,
missingPropsDescriptionHttp,
missingPropsDescriptionDir,
badSourceName,
badSourceDescription,
tsVersion,
Expand Down Expand Up @@ -45,14 +47,16 @@ function withPrecedingStatement(code) {
function makeComponentTestCase ({
ruleName,
name = `${ruleName}-test`,
validComponent = valid,
validComponents = [
valid,
],
invalidComponent,
errorMessage,
}) {
return {
name,
ruleName,
validComponent,
validComponents,
invalidComponent,
errorMessage,
};
Expand Down Expand Up @@ -91,25 +95,21 @@ const componentTestConfigs = [
},
{
ruleName: "props-label",
validComponent: missingPropsLabelTimer,
invalidComponent: missingPropsLabel,
errorMessage: "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props",
},
{
ruleName: "props-label",
validComponent: missingPropsLabelHttp,
validComponents: [
missingPropsLabelTimer,
missingPropsLabelHttp,
missingPropsLabelDir,
],
invalidComponent: missingPropsLabel,
errorMessage: "Component prop test must have a label. See https://pipedream.com/docs/components/guidelines/#props",
},
{
ruleName: "props-description",
validComponent: missingPropsDescriptionTimer,
invalidComponent: missingPropsDescription,
errorMessage: "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props",
},
{
ruleName: "props-description",
validComponent: missingPropsDescriptionHttp,
validComponents: [
missingPropsDescriptionTimer,
missingPropsDescriptionHttp,
missingPropsDescriptionDir,
],
invalidComponent: missingPropsDescription,
errorMessage: "Component prop test must have a description. See https://pipedream.com/docs/components/guidelines/#props",
},
Expand Down Expand Up @@ -138,19 +138,19 @@ componentTestCases.forEach((testCase) => {
const {
name,
ruleName,
validComponent,
validComponents,
invalidComponent,
errorMessage,
} = testCase;
ruleTester.run(name, rules[ruleName], {
valid: [
valid: validComponents.map((component) => ([
{
code: convertObjectToCJSExportString(validComponent),
code: convertObjectToCJSExportString(component),
},
{
code: convertObjectToESMExportString(validComponent),
code: convertObjectToESMExportString(component),
},
],
])).flat(),
invalid: [
{
code: convertObjectToCJSExportString(invalidComponent),
Expand Down