Skip to content

Commit 22ab1bb

Browse files
committed
Adding no-ts-version rule
1 parent 444f442 commit 22ab1bb

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

index.js

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

221+
function componentVersionTsMacroCheck(context, node) {
222+
const versionProp = checkComponentIsSourceAndReturnTargetProp(node, "version");
223+
if (!versionProp) return;
224+
if (versionProp?.value?.value.includes("{{ts}}")) {
225+
context.report({
226+
node: versionProp,
227+
message: "{{ts}} macro should be removed before committing",
228+
});
229+
}
230+
}
231+
221232
// Rules run on two different AST node types: ExpressionStatement (CJS) and Program (ESM)
222233
module.exports = {
223234
rules: {
@@ -341,5 +352,17 @@ module.exports = {
341352
};
342353
},
343354
},
355+
"no-ts-version": {
356+
create: function (context) {
357+
return {
358+
ExpressionStatement(node) {
359+
componentVersionTsMacroCheck(context, node);
360+
},
361+
Program(node) {
362+
componentVersionTsMacroCheck(context, node);
363+
},
364+
};
365+
},
366+
},
344367
},
345368
};

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.0",
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: "source",
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)