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
41 changes: 19 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ function isModuleExports(node) {
}

function isDefaultExport(node) {
if (!node) return false;
if (node.type !== "Program" || !node.body || !node.body.length) return false;
if (node?.body[0]?.type !== "ExportDefaultDeclaration") return false;
return true;
return node?.type === "ExportDefaultDeclaration";
}

function isObjectWithProperties(node) {
Expand Down Expand Up @@ -49,7 +46,7 @@ function findPropertyWithName(name, propertyArray) {
function componentContainsPropertyCheck(context, node, propertyName, message) {
let component;
if (isDefaultExport(node)) {
component = node?.body[0]?.declaration;
component = node.declaration;
}

if (node.expression) {
Expand Down Expand Up @@ -85,9 +82,8 @@ function getProps(moduleProperties) {
function componentPropsContainsPropertyCheck(context, node, propertyName) {
let component;
if (isDefaultExport(node)) {
component = node?.body[0]?.declaration;
component = node.declaration;
}

if (node.expression) {
const {
left,
Expand Down Expand Up @@ -125,7 +121,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
function optionalComponentPropsHaveDefaultProperty(context, node) {
let component;
if (isDefaultExport(node)) {
component = node?.body[0]?.declaration;
component = node.declaration;
}

if (node.expression) {
Expand Down Expand Up @@ -172,7 +168,7 @@ function optionalComponentPropsHaveDefaultProperty(context, node) {
function checkComponentIsSourceAndReturnTargetProp(node, propertyName) {
let component;
if (isDefaultExport(node)) {
component = node?.body[0]?.declaration;
component = node.declaration;
}

if (node.expression) {
Expand Down Expand Up @@ -221,7 +217,7 @@ function componentSourceDescriptionCheck(context, node) {
function componentVersionTsMacroCheck(context, node) {
let component;
if (isDefaultExport(node)) {
component = node?.body[0]?.declaration;
component = node.declaration;
}

if (node.expression) {
Expand All @@ -247,7 +243,8 @@ function componentVersionTsMacroCheck(context, node) {
}
}

// Rules run on two different AST node types: ExpressionStatement (CJS) and Program (ESM)
// Rules run on two different AST node types: ExpressionStatement (CJS) and
// ExportDefaultDeclaration (ESM)
module.exports = {
rules: {
"required-properties-key": {
Expand All @@ -256,7 +253,7 @@ module.exports = {
ExpressionStatement(node) {
componentContainsPropertyCheck(context, node, "key");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentContainsPropertyCheck(context, node, "key");
},
};
Expand All @@ -268,7 +265,7 @@ module.exports = {
ExpressionStatement(node) {
componentContainsPropertyCheck(context, node, "name");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentContainsPropertyCheck(context, node, "name");
},
};
Expand All @@ -280,7 +277,7 @@ module.exports = {
ExpressionStatement(node) {
componentContainsPropertyCheck(context, node, "version");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentContainsPropertyCheck(context, node, "version");
},
};
Expand All @@ -292,7 +289,7 @@ module.exports = {
ExpressionStatement(node) {
componentContainsPropertyCheck(context, node, "description");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentContainsPropertyCheck(context, node, "description");
},
};
Expand All @@ -304,7 +301,7 @@ module.exports = {
ExpressionStatement(node) {
componentContainsPropertyCheck(context, node, "type", "Components must export a type property (\"source\" or \"action\")");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentContainsPropertyCheck(context, node, "type", "Components must export a type property (\"source\" or \"action\")");
},
};
Expand All @@ -316,7 +313,7 @@ module.exports = {
ExpressionStatement(node) {
componentPropsContainsPropertyCheck(context, node, "label");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentPropsContainsPropertyCheck(context, node, "label");
},
};
Expand All @@ -328,7 +325,7 @@ module.exports = {
ExpressionStatement(node) {
componentPropsContainsPropertyCheck(context, node, "description");
},
Program(node) {
ExportDefaultDeclaration(node) {
componentPropsContainsPropertyCheck(context, node, "description");
},
};
Expand All @@ -340,7 +337,7 @@ module.exports = {
ExpressionStatement(node) {
optionalComponentPropsHaveDefaultProperty(context, node);
},
Program(node) {
ExportDefaultDeclaration(node) {
optionalComponentPropsHaveDefaultProperty(context, node);
},
};
Expand All @@ -352,7 +349,7 @@ module.exports = {
ExpressionStatement(node) {
componentSourceNameCheck(context, node);
},
Program(node) {
ExportDefaultDeclaration(node) {
componentSourceNameCheck(context, node);
},
};
Expand All @@ -364,7 +361,7 @@ module.exports = {
ExpressionStatement(node) {
componentSourceDescriptionCheck(context, node);
},
Program(node) {
ExportDefaultDeclaration(node) {
componentSourceDescriptionCheck(context, node);
},
};
Expand All @@ -376,7 +373,7 @@ module.exports = {
ExpressionStatement(node) {
componentVersionTsMacroCheck(context, node);
},
Program(node) {
ExportDefaultDeclaration(node) {
componentVersionTsMacroCheck(context, node);
},
};
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": "eslint-plugin-pipedream",
"version": "0.2.1",
"version": "0.2.2",
"description": "ESLint plugin for Pipedream components: https://pipedream.com/docs/components/api/",
"main": "index.js",
"scripts": {
Expand Down
Loading