Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Make tag matching case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
fedragon committed Oct 27, 2015
1 parent e37dfa8 commit c418a4c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# sbt-todolist

Finds _work in progress_ tags (`TODO`, `FIXME`, ...) in source files and prints them to the console.
The plugin performs a case insensitive search, matching any of the defined tags provided that it is followed by (one or more) whitespaces or `:`s.

## Installation

Expand Down Expand Up @@ -62,3 +63,5 @@ and
The tags to look for can be redefined by adding the following line to your `build.sbt`:

todosTags := Set("<a tag>", "<another tag>")

The plugin performs case insensitive searches so the capitalization of a tag does not influence the outcome.
9 changes: 6 additions & 3 deletions TodoListPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.fedragon

import sbt._
import Keys._
import scala.util.matching.Regex

object TodoListPlugin extends AutoPlugin {
object autoImport {
Expand All @@ -26,10 +27,10 @@ object TodoListPlugin extends AutoPlugin {
def withTodolistSettings[T](t: TaskKey[T], c: Configuration): Seq[Project.Setting[_]] =
inConfig(c)((t in c) <<= (t in c).dependsOn(todos))

val compileWithTodolistSettings: Seq[Project.Setting[_]] =
val compileWithTodolistSettings: Seq[Def.Setting[_]] =
withTodolistSettings(compile, Compile)

val testWithTodolistSettings: Seq[Project.Setting[_]] =
val testWithTodolistSettings: Seq[Def.Setting[_]] =
withTodolistSettings(test, Test)
}

Expand All @@ -41,12 +42,14 @@ object TodoList {
s"$color$msg$RESET"

def apply(base: File, sources: Seq[File], tags: Set[String]): Unit = {
val regexes = tags.map(t => new Regex(s"""(?i).*${t}[\\s|:]+.*"""))

sources.foreach { file =>
val bs = Source.fromFile(file)
try {
val todos = bs.getLines.zipWithIndex.flatMap {
case (line, index) =>
if(tags.exists(line.contains)) Some((line, index + 1))
if(regexes.exists(_.findFirstMatchIn(line).isDefined)) Some((line, index + 1))
else None
}

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.4"
version in ThisBuild := "0.5"

0 comments on commit c418a4c

Please sign in to comment.