1 | ![leasot](media/leasot.png)
|
2 |
|
3 | > Parse and output TODOs and FIXMEs from comments in your files
|
4 |
|
5 | [![NPM Version](http://img.shields.io/npm/v/leasot.svg?style=flat)](https://npmjs.org/package/leasot)
|
6 | [![NPM Downloads](http://img.shields.io/npm/dm/leasot.svg?style=flat)](https://npmjs.org/package/leasot)
|
7 | [![Build Status](http://img.shields.io/travis/pgilad/leasot.svg?style=flat)](https://travis-ci.org/pgilad/leasot)
|
8 |
|
9 | Easily extract, collect and report TODOs and FIXMEs in your code. This project uses regex in order
|
10 | to extract your todos from comments.
|
11 |
|
12 | ![Basic output example of leasot](media/table.png)
|
13 |
|
14 | ## Comment format
|
15 |
|
16 | `TODO: add some info`
|
17 |
|
18 | - Spaces are optional.
|
19 | - Colon is optional.
|
20 | - Must be in a comment (line or block) in its' own line (`some code(); //TODO: do something` is not supported).
|
21 | - Can be prefixed with a @ (i.e @TODO).
|
22 | - Spaces are trimmed around comment text.
|
23 | - Supported default types are `TODO` and `FIXME` - case insensitive.
|
24 | - Additional types can be added (using `tags` in cli and `customTags` in `leasot.parse`)
|
25 | - New extensions can be associated with bundled parsers as many languages have overlapping syntax
|
26 |
|
27 | ## Supported languages:
|
28 |
|
29 | | Filetype | Extension | Notes | Parser Name |
|
30 | | ------------ | -------------------- | -----------------------------------| ------------------- |
|
31 | | C# | `.cs` | Supports `// and /* */` comments. | defaultParser |
|
32 | | C++/C | `.cpp` `.c` `.h` | Supports `// and /* */` comments. | defaultParser |
|
33 | | CSS | `.css` | Supports `/* */` comments. | defaultParser |
|
34 | | Coffee-React | `.cjsx` | Supports `#` comments. | coffeeParser |
|
35 | | Coffeescript | `.coffee` | Supports `#` comments. | coffeeParser |
|
36 | | EJS | `.ejs` | Supports `<!-- -->` and `<%# %>` | ejsParser |
|
37 | | Erb | `.erb` | Supports `<!-- -->` | twigParser |
|
38 | | Erlang | `.erl` `.hrl` | Supports `%` comments. | erlangParser |
|
39 | | Go | `.go` | Supports `// and /* */` comments. | defaultParser |
|
40 | | HTML | `.html` `.htm` | Supports `<!-- -->` | twigParser |
|
41 | | Haml | `.haml` | Supports `/ -# <!-- --> and <%# %>`| twigParser |
|
42 | | Handlebars | `.hbs` `.handlebars` | Supports `{{! }}` and `{{!-- --}}` | hbsParser |
|
43 | | Haskell | `.hs` | Supports `--` | haskellParser |
|
44 | | Hogan | `.hgn` `.hogan` | Supports `{{! }}` and `{{!-- --}}` | hbsParser |
|
45 | | Jade | `.jade` | Supports `//` and `//-` comments. | jadeParser |
|
46 | | Javascript | `.js` `.es` `.es6` | Supports `// and /* */` comments | defaultParser |
|
47 | | Jsx | `.jsx` | Supports `// and /* */` comments. | defaultParser |
|
48 | | Less | `.less` | Supports `// and /* */` comments. | defaultParser |
|
49 | | Mustache | `.mustache` | Supports `{{! }}` and `{{!-- --}}` | hbsParser |
|
50 | | PHP | `.php` | Supports `// and /* */` comments. | defaultParser |
|
51 | | Pascal | `.pas` | Supports `// and { }` comments. | pascalParser |
|
52 | | Perl | `.pl`, `.pm` | Supports `#` comments. | coffeeParser |
|
53 | | Python | `.py` | Supports `"""` and `#` comments. | pythonParser |
|
54 | | Ruby | `.rb` | Supports `#` comments. | coffeeParser |
|
55 | | Sass | `.sass` `.scss` | Supports `// and /* */` comments. | defaultParser |
|
56 | | Shell | `.sh` `.zsh` `.bash` | Supports `#` comments. | coffeeParser |
|
57 | | SilverStripe | `.ss` | Supports `<%-- --%>` comments. | ssParser |
|
58 | | Stylus | `.styl` | Supports `// and /* */` comments. | defaultParser |
|
59 | | Twig | `.twig` | Supports `{# #}` and `<!-- -->` | twigParser |
|
60 | | Typescript | `.ts` | Supports `// and /* */` comments. | defaultParser |
|
61 |
|
62 | Javascript is the default parser.
|
63 |
|
64 | **PRs for additional filetypes is most welcomed!!**
|
65 |
|
66 | ## Usage
|
67 |
|
68 | ### Command Line
|
69 |
|
70 | #### Installation
|
71 |
|
72 | ```sh
|
73 | $ npm install --global leasot
|
74 | ```
|
75 |
|
76 | #### Examples
|
77 |
|
78 | ```sh
|
79 | ❯ leasot --help
|
80 |
|
81 | Usage: leasot [options] <file ...>
|
82 |
|
83 | Parse and output TODOs and FIXMEs from comments in your files
|
84 |
|
85 | Options:
|
86 |
|
87 | -h, --help output usage information
|
88 | -V, --version output the version number
|
89 | -r, --reporter [reporter] use reporter (table|json|xml|markdown|raw) (default: table)
|
90 | -t, --filetype [filetype] force the filetype to parse. Useful for streams (default: .js)
|
91 | -T, --tags <tags> add additional comment types to find (alongside todo & fixme)
|
92 | -S, --skip-unsupported skip unsupported filetypes
|
93 | -I, --inline-files parse possible inline files
|
94 | -A, --associate-parser [ext,parser] associate unknown extensions with bundled parsers (parser optional / default: defaultParser)
|
95 |
|
96 | Examples:
|
97 |
|
98 | # Check a specific file
|
99 | $ leasot index.js
|
100 |
|
101 | # Check php files with glob
|
102 | $ leasot **/*.php
|
103 |
|
104 | # Check multiple different filetypes
|
105 | $ leasot app/**/*.js test.rb
|
106 |
|
107 | # Use the json reporter
|
108 | $ leasot --reporter json index.js
|
109 |
|
110 | # Search for REVIEW comments as well
|
111 | $ leasot --tags review index.js
|
112 |
|
113 | # Export TODOS as markdown to a TODO.md file
|
114 | $ leasot --reporter markdown app/**/*.py > TODO.md
|
115 |
|
116 | # Check a stream specifying the filetype as coffee
|
117 | $ cat index.coffee | leasot --filetype .coffee
|
118 | ```
|
119 |
|
120 | ### Programmatic
|
121 |
|
122 | #### Installation
|
123 |
|
124 | ```sh
|
125 | $ npm install --save-dev leasot
|
126 | ```
|
127 |
|
128 | #### Examples
|
129 |
|
130 | ```js
|
131 | var fs = require('fs');
|
132 | var leasot = require('leasot');
|
133 |
|
134 | var contents = fs.readFileSync('./contents.js', 'utf8');
|
135 | // get the filetype of the file, or force a special parser
|
136 | var filetype = path.extname('./contents.js');
|
137 | // add file for better reporting
|
138 | var file = 'contents.js';
|
139 | var todos = leasot.parse({ext: filetype,content: contents,fileName: file});
|
140 |
|
141 | // -> todos now contains the array of todos/fixme parsed
|
142 |
|
143 | var output = leasot.reporter(todos, {
|
144 | reporter: 'json',
|
145 | spacing: 2
|
146 | });
|
147 |
|
148 | console.log(output);
|
149 | // -> json output of the todos
|
150 | ```
|
151 |
|
152 | ### Build Time
|
153 |
|
154 | * [gulp-todo](https://github.com/pgilad/gulp-todo)
|
155 | * [broccoli-leasot](https://github.com/sivakumar-kailasam/broccoli-leasot)
|
156 |
|
157 | ## API
|
158 |
|
159 | ```js
|
160 | var leasot = require('leasot');
|
161 | ```
|
162 |
|
163 | `leasot` exposes the following API:
|
164 |
|
165 | ### .associateExtWithParser(parsers)
|
166 |
|
167 | Associates a bundled parser with a new extension.
|
168 |
|
169 | The `parsers` parameter must be completed in the following format:
|
170 |
|
171 | ```js
|
172 | {
|
173 | '.cls': {
|
174 | parserName: 'defaultParser'
|
175 | }
|
176 | }
|
177 | ```
|
178 |
|
179 | ### .isExtSupported(extension)
|
180 |
|
181 | Check whether extension is supported by parser.
|
182 |
|
183 | Specify an extension including the prefixing dot, for example:
|
184 |
|
185 | `leasot.isExtSupported('.js'); //-> true`
|
186 |
|
187 | **Returns**: `Boolean`
|
188 |
|
189 | ### .parse(options)
|
190 |
|
191 | | Name | Type | Required | Default | Description |
|
192 | | ---- | ---- | -------- | ------- | ----------- |
|
193 | | `ext` | `string` | Yes | | The extension the parse as including a prefixing dot. |
|
194 | | `content` | `string` | Yes | | Content to parse |
|
195 | | `fileName` | `string` | No | | fileName to attach to todos output |
|
196 | | `customTags` | `array` | No | `[]` | Additional tags (comment types) to search for (alongside todo & fixme) |
|
197 | | `withIncludedFiles` | `boolean` | No | `false` | Parse also possible included file types (for example: `css` inside a `php` file |
|
198 | | `associateParser` | `object` | No | | See `.associateExtWithParser` for syntax |
|
199 |
|
200 | **Returns**: `array` of comments.
|
201 |
|
202 | ```js
|
203 | [{
|
204 | file: 'parsedFile.js',
|
205 | text: 'comment text',
|
206 | kind: 'TODO',
|
207 | line: 8
|
208 | }]
|
209 | ```
|
210 |
|
211 | ### .reporter(comments, config)
|
212 |
|
213 | Use the specified reporter to report the comments.
|
214 |
|
215 | `comments` is the array of comments received from `leasot.parse()`.
|
216 |
|
217 | `config` is an object that will also be passed to the reporter itself (allowing custom options for each reporter).
|
218 |
|
219 | It may also contain the specified reporter:
|
220 |
|
221 | #### config.reporter
|
222 |
|
223 | Can be a string indicating the [built-in reporter](#built-in-reporters) to use,
|
224 | or an external library used as a reporter.
|
225 |
|
226 | Could also be a custom function `(comments, config)`
|
227 |
|
228 | **Type**: `String|Function`
|
229 |
|
230 | **Required**: `false`
|
231 |
|
232 | **Default**: `raw`
|
233 |
|
234 | ## Built-in Reporters
|
235 |
|
236 | - json
|
237 | - xml
|
238 | - raw
|
239 | - table
|
240 | - markdown
|
241 |
|
242 | Each reporter might contain config params that are useful only for that reporter:
|
243 |
|
244 | ### Markdown
|
245 |
|
246 | Returns a markdown version of the todos.
|
247 |
|
248 | ### Options
|
249 |
|
250 | #### newLine
|
251 |
|
252 | How to separate lines in the output file. Defaults to your OS's default line separator.
|
253 |
|
254 | **Type**: `String`
|
255 |
|
256 | **Default**: `Your system default line feed`
|
257 |
|
258 | ### padding
|
259 |
|
260 | How many `newLine`s should separate between comment type blocks.
|
261 |
|
262 | **Type**: `Number`
|
263 |
|
264 | **Default**: `2`
|
265 |
|
266 | **Minimum**: `0`
|
267 |
|
268 | ### transformHeader(kind)
|
269 |
|
270 | Control the output of a header for each comment kind (*i.e todo, fixme*).
|
271 |
|
272 | **Type**: `Function`
|
273 |
|
274 | **Default**:
|
275 | ```js
|
276 | transformHeader: function (kind) {
|
277 | return ['### ' + kind + 's',
|
278 | '| Filename | line # | ' + kind,
|
279 | '|:------|:------:|:------'
|
280 | ];
|
281 | }
|
282 | ```
|
283 |
|
284 | **kind**: will be be passed as the comment kind (todo/fixme).
|
285 |
|
286 | **Returns**: `String[]|String`
|
287 |
|
288 | You are expected to return either an `Array of strings` or just a `string`. If you return an array - each item will be separated by a newline in the output.
|
289 |
|
290 | ### transformComment(file, line, text, kind)
|
291 |
|
292 | Control the output for each comment.
|
293 |
|
294 | **Type**: `Function`
|
295 |
|
296 | **Default**:
|
297 | ```js
|
298 | transformComment: function (file, line, text, kind) {
|
299 | return ['| ' + file + ' | ' + line + ' | ' + text];
|
300 | },
|
301 | ```
|
302 |
|
303 | **file**: filename the comment was in.
|
304 |
|
305 | **line**: line of comment.
|
306 |
|
307 | **text**: comment text
|
308 |
|
309 | **kind**: will be be passed as the comment kind (todo/fixme).
|
310 |
|
311 | **Returns**: `String[]|String`
|
312 |
|
313 | You are expected to return either an `Array of strings` or just a `string`. If you return an array - each item will be separated by a newline in the output.
|
314 |
|
315 | ### Table
|
316 |
|
317 | Returns a pretty formatted table of the todos.
|
318 |
|
319 | ### Raw
|
320 |
|
321 | Just returns the raw javascript todos
|
322 |
|
323 | ### JSON
|
324 |
|
325 | Return a JSON valid representation of the todos.
|
326 |
|
327 | #### Options
|
328 |
|
329 | ##### spacing
|
330 |
|
331 | Type: `Number`
|
332 |
|
333 | Default: `2`
|
334 |
|
335 | ### XML
|
336 |
|
337 | Return an unformatted XML valid representation of the todos.
|
338 |
|
339 | Parsed using [json2xml](https://github.com/estheban/node-json2xml)
|
340 |
|
341 | #### Options
|
342 |
|
343 | ##### header
|
344 |
|
345 | Whether to include xml header
|
346 |
|
347 | Type: `Boolean`
|
348 |
|
349 | Default: `true`
|
350 |
|
351 | ##### attributes_key
|
352 |
|
353 | See https://github.com/estheban/node-json2xml#options--behaviour
|
354 |
|
355 | Type: `Boolean`
|
356 |
|
357 | Default: `undefined`
|
358 |
|
359 | ## License
|
360 |
|
361 | MIT ©[Gilad Peleg](http://giladpeleg.com)
|