You'll never have to deal with outdated TODO comments again

Max Prilutskiy - May 14 '23 - - Dev Community

Have you ever noticed outdated // TODO: comments in your codebase that should have been addressed ages ago? 🤔

Well, how about this then:

// This will raise an error:
// TODO: 2020-01-01: This is an expired TODO comment.
Enter fullscreen mode Exit fullscreen mode

Looks awesome, huh?

Let's discuss how we can do something like that.


Introducing the eslint-plugin-no-expired-todo-comments, a handy tool that prevents TODO comments with expired dates from cluttering your code.

In this blog post, we'll walk through the installation, usage, and benefits of using that tiny plugin to maintain a cleaner codebase.

Btw, the work was inspired by @parker_codes's parker-codes/todo-by, check it out too!

What is it?

The eslint-plugin-no-expired-todo-comments is an ESLint plugin that provides a new rule for detecting TODO comments with expired dates. This plugin ensures that you don't have any outdated TODO comments in your codebase, helping you keep your code clean and organized.

Installation

You can easily install the plugin using npm, yarn, or pnpm, whatever you use basically, as shown below:

npm install eslint-plugin-no-expired-todo-comments --save-dev
# or
yarn add eslint-plugin-no-expired-todo-comments --dev
# or
pnpm add eslint-plugin-no-expired-todo-comments --save-dev
Enter fullscreen mode Exit fullscreen mode

Usage

Once you've installed the plugin, it's time to start using it! Simply add the no-expired-todo-comments rule to your ESLint configuration:

// .eslintrc.js
module.exports = {
  plugins: ["no-expired-todo-comments"],
  rules: {
    "no-expired-todo-comments/no-expired-todo-comments": "error",
  },
};
Enter fullscreen mode Exit fullscreen mode

Now, whenever you have a TODO comment with an expired date in your codebase, ESLint will raise an error, prompting you to address it before moving forward:

// This will raise an error:
// TODO: 2020-01-01: This is an expired TODO comment.
Enter fullscreen mode Exit fullscreen mode

As simple as that!

Benefits

By using eslint-plugin-no-expired-todo-comments, you can:

  1. Keep your codebase clean and organized by removing unnecessary and outdated TODO comments.
  2. Ensure that your team stays on top of tasks, as expired TODO comments will now trigger errors.
  3. Improve code quality by addressing TODO comments in a timely manner.

Contributing

The project welcomes contributions from the community! If you encounter any bugs or issues, please open an issue on the project's GitHub page. If you'd like to contribute code, please fork the project and submit a pull request with your changes.

Conclusion

In summary, the plugin above is a useful tool for maintaining a clean and organized codebase by preventing outdated TODO comments. With this plugin, you'll never have to worry about forgetting or neglecting important tasks buried in your code.

And finally, a little programming joke to wrap things up:

Why do programmers always mix up Christmas and Halloween? 🎃 🎄

Because Oct 31 == Dec 25! 😂

Denzel laughing with a delay

Happy coding, and may your TODO comments never get forgotten again! 😉


P.S.: If you liked this - you might like some other things I've done recently:

How I Sliced Deployment Times to a Fraction and Achieved Lightning-Fast Deployments to Production with GitHub Actions

AI-powered changelog updates on Slack, every Monday, with GitHub Actions

Follow me on Twitter: @MaxPrilutskiy

. . . .