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
58 changes: 58 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,52 @@ function componentVersionTsMacroCheck(context, node) {
}
}

function componentActionAnnotationsCheck(context, node) {
const component = getComponentFromNode(node);

if (!component) return;
const { properties } = component;

const typeProp = findPropertyWithName("type", properties);
if (typeProp?.value?.value !== "action") return;

const annotationsProp = findPropertyWithName("annotations", properties);

// Error 1 - annotations missing entirely
if (!annotationsProp) {
context.report({
node: component,
message: "Action component is missing required 'annotations' object",
});
return;
}

// Error 2 - annotations is not an object expression
if (annotationsProp.value.type !== "ObjectExpression") {
context.report({
node: annotationsProp.value,
message: "Property 'annotations' must be an object expression",
});
return;
}

// Error 3 - required keys missing
const requiredKeys = [
"destructiveHint",
"openWorldHint",
"readOnlyHint",
];

for (const requiredKey of requiredKeys) {
if (!astIncludesProperty(requiredKey, annotationsProp.value.properties)) {
context.report({
node: annotationsProp.value,
message: `Property 'annotations' is missing required key: '${requiredKey}'`,
});
}
}
}

// Rules run on two different AST node types: ExpressionStatement (CJS) and
// ExportDefaultDeclaration (ESM)
module.exports = {
Expand Down Expand Up @@ -347,5 +393,17 @@ module.exports = {
};
},
},
"action-annotations": {
create: function (context) {
return {
ExpressionStatement(node) {
componentActionAnnotationsCheck(context, node);
},
ExportDefaultDeclaration(node) {
componentActionAnnotationsCheck(context, node);
},
};
},
},
},
};
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.5",
"version": "0.3.0",
"description": "ESLint plugin for Pipedream components: https://pipedream.com/docs/components/api/",
"main": "index.js",
"scripts": {
Expand Down
38 changes: 38 additions & 0 deletions tests/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,42 @@ module.exports = {
type: "action",
version: "0.0.{{ts}}",
},
validActionWithAnnotations: {
key: "test",
name: "Test",
description: "foo",
type: "action",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: false,
readOnlyHint: true,
},
},
actionMissingAnnotations: {
key: "test",
name: "Test",
description: "foo",
type: "action",
version: "0.0.1",
},
actionMissingAnnotationKey: {
key: "test",
name: "Test",
description: "foo",
type: "action",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: false,
},
},
actionInvalidAnnotations: {
key: "test",
name: "Test",
description: "foo",
type: "action",
version: "0.0.1",
annotations: "invalid",
},
};
31 changes: 31 additions & 0 deletions tests/rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const {
badSourceName,
badSourceDescription,
tsVersion,
validActionWithAnnotations,
actionMissingAnnotations,
actionMissingAnnotationKey,
actionInvalidAnnotations,
} = require("./components");

const ruleTester = new RuleTester({
Expand Down Expand Up @@ -129,6 +133,33 @@ const componentTestConfigs = [
invalidComponent: tsVersion,
errorMessage: "{{ts}} macro should be removed before committing",
},
{
name: "action-annotations-missing",
ruleName: "action-annotations",
validComponents: [
validActionWithAnnotations,
],
invalidComponent: actionMissingAnnotations,
errorMessage: "Action component is missing required 'annotations' object",
},
{
name: "action-annotations-missing-key",
ruleName: "action-annotations",
validComponents: [
validActionWithAnnotations,
],
invalidComponent: actionMissingAnnotationKey,
errorMessage: "Property 'annotations' is missing required key: 'readOnlyHint'",
},
{
name: "action-annotations-invalid",
ruleName: "action-annotations",
validComponents: [
validActionWithAnnotations,
],
invalidComponent: actionInvalidAnnotations,
errorMessage: "Property 'annotations' must be an object expression",
},
];

const componentTestCases = componentTestConfigs.map(makeComponentTestCase);
Expand Down