Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRI-712] Create an ESLint plugin to make sure task keys are unique inside a Job run function #206

Closed
ericallam opened this issue Jul 22, 2023 · 13 comments
Labels
💎 Bounty Improvement Created by Linear-GitHub Sync 💰 Rewarded

Comments

@ericallam
Copy link
Member

ericallam commented Jul 22, 2023

Accidentally using duplicate task keys inside an individual job can lead to unexpected results (see our docs for more info: https://trigger.dev/docs/documentation/concepts/resumability). It would be great to create an ESLint plugin that can detect this.

TRI-712

@ericallam ericallam changed the title Create an ESLint plugin to make sure task keys are unique inside a Job run function [TRI-712] Create an ESLint plugin to make sure task keys are unique inside a Job run function Jul 22, 2023
@maige-app maige-app bot added bug Something isn't working area/platforms labels Jul 22, 2023
@ericallam ericallam added Improvement Created by Linear-GitHub Sync and removed bug Something isn't working area/platforms labels Jul 22, 2023
@ericallam
Copy link
Member Author

/bounty $100

@algora-pbc
Copy link

algora-pbc bot commented Jul 26, 2023

💎 $100 bounty created by ericallam
🙋 If you start working on this, comment /attempt #206 to notify everyone
👉 To claim this bounty, submit a pull request that includes the text /claim #206 somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to triggerdotdev/trigger.dev!

Attempt Started (GMT+0) Solution
🔴 @Ashutosh-Bhadauriya Jul 26, 2023, 4:49:50 PM WIP
🔴 @tobihans Jul 26, 2023, 4:50:39 PM WIP
🟢 @Anshul1811 Jul 26, 2023, 6:39:55 PM WIP
🟡 @ologbonowiwi Aug 12, 2023, 2:59:07 AM #324

@Ashutosh-Bhadauriya
Copy link
Contributor

/attempt #206

@algora-pbc
Copy link

algora-pbc bot commented Jul 26, 2023

Note: The user @Ashutosh-Bhadauriya is already attempting to complete issue #206 and claim the bounty. If you attempt to complete the same issue, there is a chance that @Ashutosh-Bhadauriya will complete the issue first, and be awarded the bounty. We recommend discussing with @Ashutosh-Bhadauriya and potentially collaborating on the same solution versus creating an alternate solution.

@Anshul1811
Copy link

/attempt #206

@Ashutosh-Bhadauriya
Copy link
Contributor

@ericallam just to confirm. I should be doing this inside config-packages/eslint-config-custom, right?

@b4s36t4
Copy link

b4s36t4 commented Jul 27, 2023

@ericallam could you please verify below test-cases should works for the plugin-rule or maybe I'm missing any rule.

Test Cases
/**
 * @fileoverview No Unique key
 * @author no-unique-key
 */
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require("../../../lib/rules/no-unique-key"),
  RuleTester = require("eslint").RuleTester;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });
ruleTester.run("no-unique-key", rule, {
  valid: [
    // give me some code that won't trigger a warning
    {
      code: `
      new Job(client, {
        id: "event-1",
        name: "Run when the foo.bar event happens",
        version: "0.0.1",
        trigger: eventTrigger({
          name: "foo.bar",
        }),
        run: async (payload, io, ctx) => {
          await io.slack.postMessage("⭐️ New Star", {
            channel: "C04GWUTDC3W",
            text: 'hello'
          });
        },
      });
      `,
    },
    {
      code: `
      const runJob  = async (payload, io, ctx) => {
        await io.slack.postMessage("⭐️ New Star", {
          channel: "C04GWUTDC3W",
          text: 'hello'
        });
      }
      new Job(client, {
        id: "event-1",
        name: "Run when the foo.bar event happens",
        version: "0.0.1",
        trigger: eventTrigger({
          name: "foo.bar",
        }),
        run: runJob
      });
      `,
    },
  ],

  invalid: [
    {
      code: `
      new Job(client, {
        id: "event-1",
        name: "Run when the foo.bar event happens",
        version: "0.0.1",
        trigger: eventTrigger({
          name: "foo.bar",
        }),
        run: async (payload, io, ctx) => {
          await io.slack.postMessage("⭐️ New Star", {
            channel: "C04GWUTDC3W",
            text: 'hello'
          });
          await io.slack.postMessage("⭐️ New Star", {
            channel: "C04GWUTDC3W",
            text: 'hello'
          });
        },
      });
      `,
      errors: [
        {
          message:
            "'⭐️ New Star' key already exists please use different keys to execute the job",
        },
      ],
    },
  ],
});

@ologbonowiwi
Copy link
Contributor

ologbonowiwi commented Aug 12, 2023

/attempt #206

Options

@algora-pbc
Copy link

algora-pbc bot commented Aug 12, 2023

💡 @ologbonowiwi submitted a pull request that claims the bounty. You can visit your org dashboard to reward.
👉 @ologbonowiwi: To receive payouts, sign up on Algora, link your Github account and connect with Stripe on your dashboard.

@algora-pbc
Copy link

algora-pbc bot commented Aug 18, 2023

@ologbonowiwi: Your claim has been rewarded! 👉 Complete your Algora onboarding to collect the bounty.

@algora-pbc
Copy link

algora-pbc bot commented Aug 19, 2023

🎉🎈 @ologbonowiwi has been awarded $100! 🎈🎊

@ologbonowiwi
Copy link
Contributor

There's anything missing to close this @ericallam @matt-aitken?

@ologbonowiwi
Copy link
Contributor

Can we close it, guys? @matt-aitken @ericallam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty Improvement Created by Linear-GitHub Sync 💰 Rewarded
Projects
None yet
Development

No branches or pull requests

5 participants