Skip to content

Commit 1138af8

Browse files
authored
Merge pull request #4 from PipedreamHQ/ts-linting
{{ts}} version linting
2 parents 444f442 + 9224138 commit 1138af8

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,35 @@ function componentSourceDescriptionCheck(context, node) {
218218
}
219219
}
220220

221+
function componentVersionTsMacroCheck(context, node) {
222+
let component;
223+
if (isDefaultExport(node)) {
224+
component = node?.body[0]?.declaration;
225+
}
226+
227+
if (node.expression) {
228+
const {
229+
left,
230+
right,
231+
} = node.expression;
232+
if (isModuleExports(left) && isObjectWithProperties(right)) {
233+
component = right;
234+
}
235+
}
236+
237+
if (!component) return;
238+
const { properties } = component;
239+
240+
const versionProp = findPropertyWithName("version", properties);
241+
if (!versionProp) return;
242+
if (versionProp?.value?.value.includes("{{ts}}")) {
243+
context.report({
244+
node: versionProp,
245+
message: "{{ts}} macro should be removed before committing",
246+
});
247+
}
248+
}
249+
221250
// Rules run on two different AST node types: ExpressionStatement (CJS) and Program (ESM)
222251
module.exports = {
223252
rules: {
@@ -341,5 +370,17 @@ module.exports = {
341370
};
342371
},
343372
},
373+
"no-ts-version": {
374+
create: function (context) {
375+
return {
376+
ExpressionStatement(node) {
377+
componentVersionTsMacroCheck(context, node);
378+
},
379+
Program(node) {
380+
componentVersionTsMacroCheck(context, node);
381+
},
382+
};
383+
},
384+
},
344385
},
345386
};

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

tests/components.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,11 @@ module.exports = {
9595
description: "foo",
9696
type: "source",
9797
},
98+
tsVersion: {
99+
key: "test",
100+
name: "Test",
101+
description: "foo",
102+
type: "action",
103+
version: "0.0.{{ts}}",
104+
},
98105
};

tests/rules.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
missingPropsDescription,
1313
badSourceName,
1414
badSourceDescription,
15+
tsVersion,
1516
} = require("./components");
1617

1718
const ruleTester = new RuleTester({
@@ -319,3 +320,32 @@ ruleTester.run("source-description-test", rules["source-description"], {
319320
},
320321
],
321322
});
323+
324+
ruleTester.run("ts-version-test", rules["no-ts-version"], {
325+
valid: [
326+
{
327+
code: convertObjectToCJSExportString(valid),
328+
},
329+
{
330+
code: convertObjectToESMExportString(valid),
331+
},
332+
],
333+
invalid: [
334+
{
335+
code: convertObjectToCJSExportString(tsVersion),
336+
errors: [
337+
{
338+
message: "{{ts}} macro should be removed before committing",
339+
},
340+
],
341+
},
342+
{
343+
code: convertObjectToESMExportString(tsVersion),
344+
errors: [
345+
{
346+
message: "{{ts}} macro should be removed before committing",
347+
},
348+
],
349+
},
350+
],
351+
});

0 commit comments

Comments
 (0)