-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (79 loc) · 2.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// This file is part of report-todo
// Copyright (C) 2019-present Dario Giovannetti <[email protected]>
// Licensed under MIT
// https://github.com/kynikos/report-todo/blob/master/LICENSE
// TODO[setup]: Start using ES6 module imports when they're no longer
// experimental in Node.js
const {Channel} = require('queueable')
const {iterateParseFiles} = require('./iterateParseFiles')
const {generateMatches} = require('./generateMatches')
const {makeReport} = require('./makeReport')
const DEFAULT_OPTIONS = require('./defaultOptions')
// The report-todo script needs to import the default options from this module
module.exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS
// These exports are required by the bin script, which can't require them
// directly, since technically they get bundled in the report-todo library,
// they're not available as independent node_modules libraries
// TODO[setup]: Make a Babel plugin to pre-process all oneLine strings at
// compile time (turn them all into normal strings, properly dedented)
module.exports.oneLine = require('common-tags').oneLine
module.exports.commander = require('commander')
// TODO[setup]: NPM recommends also specifying 'engines' in package.json
// https://docs.npmjs.com/using-npm/developers.html
// TODO[enhancement]: Use a configuration file to sort sections in an arbitrary
// order
// TODO[enhancement]: Support comments with closing tag, e.g.
// /* some comment */
// TODO[integration]: See also https://pgilad.github.io/leasot/
// Adapt this as a plugin? Note that it also supports custom parsers
// TODO[integration]: How cool would it be if the whole thing could be
// integrated with GitHub's issue tracker etc.
module.exports.reportTodo = function reportTodo(globs, options = {}) {
const {
tags,
caseInsensitive,
labelsDelimiters,
labelsSeparator,
labels,
labelsIsBlacklist,
ignoreLineComment,
reportMode,
reportGroupBy,
reportSortBy,
reportLinksPrefix,
} = {
...DEFAULT_OPTIONS.reduce((acc, {key, value}) => {
acc[key] = value
return acc
}, {}),
...options,
}
const todoMatchesChannel = new Channel()
// Don't await iterateParseFiles(): it will asynchronously push values to the
// channel, which can then be asynchronously iterated
// Don't try to filter by tag or label at report time, do it directly at parse
// time
iterateParseFiles({
globs,
tags,
caseInsensitive,
labelsDelimiters,
labelsSeparator,
labels,
labelsIsBlacklist,
ignoreLineComment,
todoMatchesChannel,
})
const matchGenerator = generateMatches(todoMatchesChannel)
if (reportMode === 'generator') {
return matchGenerator
}
return makeReport({
matchGenerator,
reportGroupBy,
reportSortBy,
reportMode,
reportLinksPrefix,
labelsSeparator,
})
}