/reminder

🔔 Say goodbye to forgotten TODOs in your code!

Primary LanguageScalaApache License 2.0Apache-2.0

reminder

Say goodbye to forgotten TODOs in your code!

Were you ever forced to do some quick&dirty changes or hot fixes to your codebase telling yourself you will review this part of code later? Are code comments like //TODO make this better or //FIXME bring some sanity to this familiar to you? Once you put these comment in your codebase, it's easy to forget about them. Time to say goodbye to them and introduce the @reminder annotation! Simply put this annotation to the code you want to revisit in future and after selected date, this code won't compile anymore, forcing you (or your colleagues) to review it.

Make it a part of your project

Add following definitions to build.sbt:

  // 1a. enable macros for your project (Scala 2.13+ only)
  scalacOptions += "-Ymacro-annotations"

  // 1b. enable macros for your project (Scala 2.11, 2.12 only)
  addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
  
  // 2. add the Bintray resolver
  resolvers += Resolver.bintrayRepo("norcane", "reminder")
  
  // 3. add reminder as dependency
  libraryDependencies += "com.norcane" %% "reminder" % "0.2.0"

At this moment, reminder is cross compiled for Scala 2.11, 2.12 and 2.13.

Show me the code!

  import com.norcane.reminder
  
  @reminder("2200-02-02")       // <-- will compile, you have plenty of time to review this
  def someDirtyImplementation() = { ... }
  
  @reminder("2000-02-02")       // <-- will cause compile error
  def someDirtyImplementation() = { ... }
  
  @reminder("dsfwefioh")        // <-- invalid date format will also cause compile error
  def someDirtyImplementation() = { ... }
  
  @reminder("2200/02/02", dateFormat = "yyyy/MM/dd")       // <-- using custom date format
  def someDirtyImplementation() = { ... }
  
  @reminder("2200/02/02", "I really need to fix this")     // <-- using custom message
  class ReallyUglyStuff() { ... }

Ok, show me more!

Below is the definition of the @reminder annotation, with corresponding default values:

  class reminder(date: String,
                 note: String = "Please make sure that the annotated part of your codebase is still valid",
                 dateFormat: String = "yyyy-MM-dd")

Feel free to combine parameters as required.

What kind of sorcery is this?

The @reminder annotation is implemented as Scala Macro Annotation, using the Macro Paradise compiler plugin. In fact, it does nothing more than that it compares the current date and the date you set as the annotation parameter and if the set date is in past, it will cause compiler error.