Skip to content

Commit 8137396

Browse files
authored
Merge pull request #9 from js07/fix-typeerror-properties-undefined
Fix eslint failing with TypeError when default export is not an object
2 parents 6b0f0a5 + c01c763 commit 8137396

File tree

3 files changed

+25
-71
lines changed

3 files changed

+25
-71
lines changed

index.js

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

23+
function getComponentFromNode(node) {
24+
if (isDefaultExport(node) && isObjectWithProperties(node.declaration)) {
25+
return node.declaration;
26+
}
27+
28+
if (node.expression) {
29+
const {
30+
left,
31+
right,
32+
} = node.expression;
33+
if (isModuleExports(left) && isObjectWithProperties(right)) {
34+
return right;
35+
}
36+
}
37+
38+
return null;
39+
}
40+
2341
// Objects can contain key names surrounded by quotes, or not
2442
// propertyArray is the array of Property nodes in the component object
2543
function astIncludesProperty(name, propertyArray) {
@@ -44,20 +62,7 @@ function findPropertyWithName(name, propertyArray) {
4462

4563
// Does a component contain the right property? e.g. key, version
4664
function componentContainsPropertyCheck(context, node, propertyName, message) {
47-
let component;
48-
if (isDefaultExport(node)) {
49-
component = node.declaration;
50-
}
51-
52-
if (node.expression) {
53-
const {
54-
left,
55-
right,
56-
} = node.expression;
57-
if (isModuleExports(left) && isObjectWithProperties(right)) {
58-
component = right;
59-
}
60-
}
65+
const component = getComponentFromNode(node);
6166

6267
if (!component) return;
6368
if (!astIncludesProperty(propertyName, component.properties)) {
@@ -80,19 +85,7 @@ function getProps(moduleProperties) {
8085

8186
// Do component props contain the right properties? e.g. label, description
8287
function componentPropsContainsPropertyCheck(context, node, propertyName) {
83-
let component;
84-
if (isDefaultExport(node)) {
85-
component = node.declaration;
86-
}
87-
if (node.expression) {
88-
const {
89-
left,
90-
right,
91-
} = node.expression;
92-
if (isModuleExports(left) && isObjectWithProperties(right)) {
93-
component = right;
94-
}
95-
}
88+
const component = getComponentFromNode(node);
9689

9790
if (!component) return;
9891

@@ -119,20 +112,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
119112
}
120113

121114
function optionalComponentPropsHaveDefaultProperty(context, node) {
122-
let component;
123-
if (isDefaultExport(node)) {
124-
component = node.declaration;
125-
}
126-
127-
if (node.expression) {
128-
const {
129-
left,
130-
right,
131-
} = node.expression;
132-
if (isModuleExports(left) && isObjectWithProperties(right)) {
133-
component = right;
134-
}
135-
}
115+
const component = getComponentFromNode(node);
136116

137117
if (!component) return;
138118
const { properties } = component;
@@ -166,20 +146,7 @@ function optionalComponentPropsHaveDefaultProperty(context, node) {
166146
// Checks to confirm the component is a source, and returns
167147
// the node with the name specified by the user
168148
function checkComponentIsSourceAndReturnTargetProp(node, propertyName) {
169-
let component;
170-
if (isDefaultExport(node)) {
171-
component = node.declaration;
172-
}
173-
174-
if (node.expression) {
175-
const {
176-
left,
177-
right,
178-
} = node.expression;
179-
if (isModuleExports(left) && isObjectWithProperties(right)) {
180-
component = right;
181-
}
182-
}
149+
const component = getComponentFromNode(node);
183150

184151
if (!component) return;
185152
const { properties } = component;
@@ -215,20 +182,7 @@ function componentSourceDescriptionCheck(context, node) {
215182
}
216183

217184
function componentVersionTsMacroCheck(context, node) {
218-
let component;
219-
if (isDefaultExport(node)) {
220-
component = node.declaration;
221-
}
222-
223-
if (node.expression) {
224-
const {
225-
left,
226-
right,
227-
} = node.expression;
228-
if (isModuleExports(left) && isObjectWithProperties(right)) {
229-
component = right;
230-
}
231-
}
185+
const component = getComponentFromNode(node);
232186

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

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.2",
3+
"version": "0.2.3",
44
"description": "ESLint plugin for Pipedream components: https://pipedream.com/docs/components/api/",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)