Skip to content

Commit

Permalink
Added support for oldstyle TODO-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hkjels committed Feb 28, 2012
1 parent 8a0d5dc commit b5602b7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
65 changes: 38 additions & 27 deletions lib/ack.js
Expand Up @@ -6,7 +6,7 @@
var fs = require('./fs')
, join = require('path').join

var KEYWORDS = ['TODO', 'BUG', 'FIXME', 'OPTIMIZE'].join('|')
var KEYWORDS = ['TODO', 'BUG', 'FIXME', 'OPTIMIZE', 'REVIEW'].join('|')
, running = 0
, concurrency = 198

Expand Down Expand Up @@ -62,40 +62,51 @@ var ack = module.exports = function ack (path, list, cb) {
linum++
if (!pattern.test(line)) continue

// Assignee is the first occurence of @\w
// Old-style comments
var matches = line.match(new RegExp('('+KEYWORDS+'):(\\d{4,}-\\d{2}-\\d{2}):([^:]+):(.*)', 'g'))
if (matches != null) {
matches = matches.toString().split(':')
var labels = ['#'+matches[0].toLowerCase(), '#due['+matches[1]+']']
, assignee = '@'+matches[2]
, title = matches[3]
, body = '';
}

var assignee = (line.match(/@[\w\[\d\]-_]*/g)||['@none'])[0]
else {
// Assignee is the first occurence of @\w

// Title is the first line of the comment
// Assignee, keyword and commentspesific characters are removed.
var assignee = (line.match(/@[\w\[\d\]-_]*/g)||['@none'])[0]

var title = line.replace(new RegExp('.*('+KEYWORDS+')'), '')
.replace(assignee, '')
.replace(/[^a-z0-9\!\]\)]*$/i, '').trim()
// Title is the first line of the comment
// Assignee, keyword and commentspesific characters are removed.

// Body is every line after the title
// Commentspesific characters are removed
var title = line.replace(new RegExp('.*('+KEYWORDS+')'), '')
.replace(assignee, '')
.replace(/[^a-z0-9\!\]\)]*$/i, '').trim()

var body = (function body() {
var next = lines.shift()
if (/[\\s]*[\\\*\%\-(" )"]{0,3}[\|]/g.test(next)) {
linum++
return next.split('|').slice(1).join('').trim()+'\n'+body()
} else {
lines.unshift(next)
return ''
}
})()
// Body is every line after the title
// Commentspesific characters are removed

// Labels are every word that starts with a hash "#"
var body = (function body() {
var next = lines.shift()
if (/[\\s]*[\\\*\%\-(" )"]{0,3}[\|]/g.test(next)) {
linum++
return next.split('|').slice(1).join('').trim()+'\n'+body()
} else {
lines.unshift(next)
return ''
}
})()

var labels = ((title+body).match(/#[\w]*[\[\]0-9\.]*/gi) || [])
labels.unshift('#'+line.match(pattern)[0])
labels.filter(function (label) { return label.length > 1 })
labels = labels.map(function (label) {
return label.toLowerCase()
})
// Labels are every word that starts with a hash "#"

var labels = ((title+body).match(/#[\w]*[\[\]0-9\.]*/gi) || [])
labels.unshift('#'+line.match(pattern)[0])
labels.filter(function (label) { return label.length > 1 })
labels = labels.map(function (label) {
return label.toLowerCase()
})
}
var done = labels[0] == '#done' ? true : false

// Final task-object
Expand Down
10 changes: 6 additions & 4 deletions lib/pool.js
Expand Up @@ -93,7 +93,11 @@ exports.find = function taskpoolFind (qargs, cb) {
matches.push(true)
}
}
else if (tlabel == qlabel.key) matches.push(true)
else {
var valexists = tlabel.indexOf('[')
tlabel = valexists != -1 ? tlabel.substr(0, valexists) : tlabel
if (tlabel == qlabel.key) matches.push(true)
}
})
})
}
Expand Down Expand Up @@ -141,9 +145,7 @@ exports.update = function taskpoolUpdate (paths, cb) {
taskpool.ack(path, project.ignore, function (err, tasks) {
if (err) return cb(err)
tasks.forEach(function (task, i) {
var exists = taskpool.db.find('__uuid__', task['__uuid__'])
if (exists) updates.modified.push(task)
else updates.added.push(task)
updates.added.push(task)

new Task(task)

Expand Down

0 comments on commit b5602b7

Please sign in to comment.