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 | - Supports both leading and trailing references. E.g. `// TODO(tregusti): Make this better` or `// TODO: Text /tregusti`
|
27 |
|
28 | ## Supported languages:
|
29 |
|
30 | | Filetype | Extension | Notes | Parser Name |
|
31 | | ------------ | -------------------- | -------------------------------------------| ------------------- |
|
32 | | C# | `.cs` | Supports `// and /* */` comments. | defaultParser |
|
33 | | C++/C | `.cpp` `.c` `.h` | Supports `// and /* */` comments. | defaultParser |
|
34 | | Coffee-React | `.cjsx` | Supports `#` comments. | coffeeParser |
|
35 | | Coffeescript | `.coffee` | Supports `#` comments. | coffeeParser |
|
36 | | Crystal | `.cr` | Supports `#` comments. | coffeeParser |
|
37 | | CSon | `.cson` | Supports `#` comments. | coffeeParser |
|
38 | | CSS | `.css` | Supports `/* */` comments. | defaultParser |
|
39 | | EJS | `.ejs` | Supports `<!-- -->` and `<%# %>` | ejsParser |
|
40 | | Erb | `.erb` | Supports `<!-- -->` and `<%# %>` | ejsParser |
|
41 | | Erlang | `.erl` `.hrl` | Supports `%` comments. | erlangParser |
|
42 | | Go | `.go` | Supports `// and /* */` comments. | defaultParser |
|
43 | | Haml | `.haml` | Supports `/ -# <!-- --> and <%# %>` | twigParser |
|
44 | | Handlebars | `.hbs` `.handlebars` | Supports `{{! }}` and `{{!-- --}}` | hbsParser |
|
45 | | Haskell | `.hs` | Supports `--` | haskellParser |
|
46 | | Hogan | `.hgn` `.hogan` | Supports `{{! }}` and `{{!-- --}}` | hbsParser |
|
47 | | HTML | `.html` `.htm` | Supports `<!-- -->` | twigParser |
|
48 | | Jade | `.jade` `.pug` | Supports `//` and `//-` comments. | jadeParser |
|
49 | | Java | `.java` | Supports `// and /* */` comments | defaultParser |
|
50 | | Javascript | `.js` `.es` `.es6` | Supports `// and /* */` comments | defaultParser |
|
51 | | Jsx | `.jsx` | Supports `// and /* */` comments. | defaultParser |
|
52 | | Kotlin | `.kt` | Supports `// and /* */` comments. | defaultParser |
|
53 | | Less | `.less` | Supports `// and /* */` comments. | defaultParser |
|
54 | | Mustache | `.mustache` | Supports `{{! }}` and `{{!-- --}}` | hbsParser |
|
55 | | Nunjucks | `.njk` | Supports `{# #}` and `<!-- -->` | twigParser |
|
56 | | Objective-C | `.m` | Supports `// and /* */` comments | defaultParser |
|
57 | | Objective-C++ | `.mm` | Supports `// and /* */` comments | defaultParser |
|
58 | | Pascal | `.pas` | Supports `// and { }` comments. | pascalParser |
|
59 | | Perl | `.pl`, `.pm` | Supports `#` comments. | coffeeParser |
|
60 | | PHP | `.php` | Supports `// and /* */` comments. | defaultParser |
|
61 | | Python | `.py` | Supports `"""` and `#` comments. | pythonParser |
|
62 | | Ruby | `.rb` | Supports `#` comments. | coffeeParser |
|
63 | | Sass | `.sass` `.scss` | Supports `// and /* */` comments. | defaultParser |
|
64 | | Scala | `.scala` | Supports `// and /* */` comments. | defaultParser |
|
65 | | Shell | `.sh` `.zsh` `.bash` | Supports `#` comments. | coffeeParser |
|
66 | | SilverStripe | `.ss` | Supports `<%-- --%>` comments. | ssParser |
|
67 | | SQL | `.sql` | Supports `--` and `/* */` comments | defaultParser & haskellParser |
|
68 | | Stylus | `.styl` | Supports `// and /* */` comments. | defaultParser |
|
69 | | Swift | `.swift` | Supports `// and /* */` comments. | defaultParser |
|
70 | | Twig | `.twig` | Supports `{# #}` and `<!-- -->` | twigParser |
|
71 | | Typescript | `.ts`, `.tsx` | Supports `// and /* */` comments. | defaultParser |
|
72 | | Vue | `.vue` | Supports `//` `/* */` `<!-- -->` comments. | twigParser |
|
73 | | Yaml | `.yaml` `.yml` | Supports `#` comments. | coffeeParser |
|
74 |
|
75 | Javascript is the default parser.
|
76 |
|
77 | **PRs for additional filetypes is most welcomed!!**
|
78 |
|
79 | ## Usage
|
80 |
|
81 | ### Command Line
|
82 |
|
83 | #### Installation
|
84 |
|
85 | ```sh
|
86 | $ npm install --global leasot
|
87 | ```
|
88 |
|
89 | #### Examples
|
90 |
|
91 | ```sh
|
92 | $ leasot --help
|
93 |
|
94 | Usage: leasot [options] <file ...>
|
95 |
|
96 | Parse and output TODOs and FIXMEs from comments in your files
|
97 |
|
98 | Options:
|
99 |
|
100 | -h, --help output usage information
|
101 | -V, --version output the version number
|
102 | -A, --associate-parser [ext,parser] associate unknown extensions with bundled parsers (parser optional / default: defaultParser)
|
103 | -i, --ignore <patterns> add ignore patterns
|
104 | -I, --inline-files parse possible inline files
|
105 | -r, --reporter [reporter] use reporter (table|json|xml|markdown|vscode|raw) (default: table)
|
106 | -S, --skip-unsupported skip unsupported filetypes
|
107 | -t, --filetype [filetype] force the filetype to parse. Useful for streams (default: .js)
|
108 | -T, --tags <tags> add additional comment types to find (alongside todo & fixme)
|
109 | -x, --exit-nicely exit with exit code 0 even if todos/fixmes are found
|
110 |
|
111 | Examples:
|
112 |
|
113 | # Check a specific file
|
114 | $ leasot index.js
|
115 |
|
116 | # Check php files with glob
|
117 | $ leasot **/*.php
|
118 |
|
119 | # Check multiple different filetypes
|
120 | $ leasot app/**/*.js test.rb
|
121 |
|
122 | # Use the json reporter
|
123 | $ leasot --reporter json index.js
|
124 |
|
125 | # Search for REVIEW comments as well
|
126 | $ leasot --tags review index.js
|
127 |
|
128 | # Add ignore pattern to filter matches
|
129 | $ leasot app/**/*.js --ignore "**/custom.js"
|
130 |
|
131 | # Search for REVIEW comments as well
|
132 | $ leasot --tags review index.js
|
133 |
|
134 | # Check a stream specifying the filetype as coffee
|
135 | $ cat index.coffee | leasot --filetype .coffee
|
136 |
|
137 | # Report from leasot parsing and filter todos using `jq`
|
138 | $ leasot tests/**/*.styl --reporter json | jq 'map(select(.kind == "TODO"))' | leasot-reporter
|
139 | ```
|
140 |
|
141 | #### Using in NPM
|
142 |
|
143 | This _package.json_ snippet shows how to include leasot in your project development environment and set up as a task (`todo`). The `todo_suppress_error` task stops leasot causing npm to error, so it can be used in a build process without halting it.
|
144 |
|
145 | ```json
|
146 | {
|
147 | "scripts": {
|
148 | "todo": "leasot src/**/*.js",
|
149 | "todo_suppress_error": "leasot src/**/*.js || true",
|
150 | },
|
151 | "devDependencies": {
|
152 | "leasot": "*"
|
153 | }
|
154 | }
|
155 | ```
|
156 |
|
157 | ### Programmatic
|
158 |
|
159 | #### Installation
|
160 |
|
161 | ```sh
|
162 | $ npm install --save-dev leasot
|
163 | ```
|
164 |
|
165 | #### Examples
|
166 |
|
167 | ```js
|
168 | var fs = require('fs');
|
169 | var leasot = require('leasot');
|
170 |
|
171 | var contents = fs.readFileSync('./contents.js', 'utf8');
|
172 | // get the filetype of the file, or force a special parser
|
173 | var filetype = path.extname('./contents.js');
|
174 | // add file for better reporting
|
175 | var file = 'contents.js';
|
176 | var todos = leasot.parse({ ext: filetype, content: contents, fileName: file });
|
177 |
|
178 | // -> todos now contains the array of todos/fixme parsed
|
179 |
|
180 | var output = leasot.reporter(todos, {
|
181 | reporter: 'json',
|
182 | spacing: 2
|
183 | });
|
184 |
|
185 | console.log(output);
|
186 | // -> json output of the todos
|
187 | ```
|
188 |
|
189 | ### Build Time
|
190 |
|
191 | * [gulp-todo](https://github.com/pgilad/gulp-todo)
|
192 | * [broccoli-leasot](https://github.com/sivakumar-kailasam/broccoli-leasot)
|
193 | * [todo-webpack-plugin](https://github.com/mikeerickson/todo-webpack-plugin)
|
194 |
|
195 | ## API
|
196 |
|
197 | ```js
|
198 | var leasot = require('leasot');
|
199 | ```
|
200 |
|
201 | `leasot` exposes the following API:
|
202 |
|
203 | ### .associateExtWithParser(parsers)
|
204 |
|
205 | Associates a bundled parser with a new extension.
|
206 |
|
207 | The `parsers` parameter must be completed in the following format:
|
208 |
|
209 | ```js
|
210 | {
|
211 | '.cls': {
|
212 | parserName: 'defaultParser'
|
213 | }
|
214 | }
|
215 |
|
216 | ```
|
217 | The `parserName` property can also be an array of parsers.
|
218 | ```js
|
219 | {
|
220 | '.sql': {
|
221 | parserName: ['defaultParser', 'haskellParser']
|
222 | }
|
223 | }
|
224 | ```
|
225 |
|
226 | ### .isExtSupported(extension)
|
227 |
|
228 | Check whether extension is supported by parser.
|
229 |
|
230 | Specify an extension including the prefixing dot, for example:
|
231 |
|
232 | `leasot.isExtSupported('.js'); //-> true`
|
233 |
|
234 | **Returns**: `Boolean`
|
235 |
|
236 | ### .parse(options)
|
237 |
|
238 | | Name | Type | Required | Default | Description |
|
239 | | ---- | ---- | -------- | ------- | ----------- |
|
240 | | `ext` | `string` | Yes | | The extension the parse as including a prefixing dot. |
|
241 | | `content` | `string` | Yes | | Content to parse |
|
242 | | `fileName` | `string` | No | | fileName to attach to todos output |
|
243 | | `customTags` | `array` | No | `[]` | Additional tags (comment types) to search for (alongside todo & fixme) |
|
244 | | `withIncludedFiles` | `boolean` | No | `false` | Parse also possible included file types (for example: `css` inside a `php` file |
|
245 | | `associateParser` | `object` | No | | See `.associateExtWithParser` for syntax |
|
246 |
|
247 | **Returns**: `array` of comments.
|
248 |
|
249 | ```js
|
250 | [{
|
251 | file: 'parsedFile.js',
|
252 | text: 'comment text',
|
253 | kind: 'TODO',
|
254 | line: 8,
|
255 | ref: 'reference'
|
256 | }]
|
257 | ```
|
258 |
|
259 | ### .reporter(comments, config)
|
260 |
|
261 | Use the specified reporter to report the comments.
|
262 |
|
263 | `comments` is the array of comments received from `leasot.parse()`.
|
264 |
|
265 | `config` is an object that will also be passed to the reporter itself (allowing custom options for each reporter).
|
266 |
|
267 | It may also contain the specified reporter:
|
268 |
|
269 | #### config.reporter
|
270 |
|
271 | Can be a string indicating the [built-in reporter](#built-in-reporters) to use,
|
272 | or an external library used as a reporter.
|
273 |
|
274 | Could also be a custom function `(comments, config)`
|
275 |
|
276 | **Type**: `String|Function`
|
277 |
|
278 | **Required**: `false`
|
279 |
|
280 | **Default**: `raw`
|
281 |
|
282 | ## Built-in Reporters
|
283 |
|
284 | - json
|
285 | - xml
|
286 | - raw
|
287 | - table
|
288 | - markdown
|
289 | - vscode
|
290 |
|
291 | Each reporter might contain config params that are useful only for that reporter:
|
292 |
|
293 | ### Markdown
|
294 |
|
295 | Returns a markdown version of the todos.
|
296 |
|
297 | ### Options
|
298 |
|
299 | #### newLine
|
300 |
|
301 | How to separate lines in the output file. Defaults to your OS's default line separator.
|
302 |
|
303 | **Type**: `String`
|
304 |
|
305 | **Default**: `Your system default line feed`
|
306 |
|
307 | ### padding
|
308 |
|
309 | How many `newLine`s should separate between comment type blocks.
|
310 |
|
311 | **Type**: `Number`
|
312 |
|
313 | **Default**: `2`
|
314 |
|
315 | **Minimum**: `0`
|
316 |
|
317 | ### transformHeader(kind)
|
318 |
|
319 | Control the output of a header for each comment kind (*i.e todo, fixme*).
|
320 |
|
321 | **Type**: `Function`
|
322 |
|
323 | **Default**:
|
324 | ```js
|
325 | transformHeader: function (kind) {
|
326 | return ['### ' + kind + 's',
|
327 | '| Filename | line # | ' + kind,
|
328 | '|:------|:------:|:------'
|
329 | ];
|
330 | }
|
331 | ```
|
332 |
|
333 | **kind**: will be be passed as the comment kind (todo/fixme).
|
334 |
|
335 | **Returns**: `String[]|String`
|
336 |
|
337 | 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.
|
338 |
|
339 | ### transformComment(file, line, text, kind, ref)
|
340 |
|
341 | Control the output for each comment.
|
342 |
|
343 | **Type**: `Function`
|
344 |
|
345 | **Default**:
|
346 | ```js
|
347 | transformComment: function (file, line, text, kind, ref) {
|
348 | return ['| ' + file + ' | ' + line + ' | ' + text];
|
349 | }
|
350 | ```
|
351 |
|
352 | **file**: filename the comment was in.
|
353 |
|
354 | **line**: line of comment.
|
355 |
|
356 | **text**: comment text. Default ''.
|
357 |
|
358 | **kind**: will be be passed as the comment kind (todo/fixme).
|
359 |
|
360 | **ref**: a reference. Default ''.
|
361 |
|
362 | **Returns**: `String[]|String`
|
363 |
|
364 | 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.
|
365 |
|
366 | ### VSCode
|
367 |
|
368 | Returns a markdown version of the todos customized for Visual Studio Code. The file names are
|
369 | transformed as URLs and the line numbers as anchors which makes them clickable when the markdown
|
370 | content produced with this reporter is opened on Visual Studio Code.
|
371 |
|
372 | ### Table
|
373 |
|
374 | Returns a pretty formatted table of the todos.
|
375 |
|
376 | ### Raw
|
377 |
|
378 | Just returns the raw javascript todos
|
379 |
|
380 | ### JSON
|
381 |
|
382 | Return a JSON valid representation of the todos.
|
383 |
|
384 | #### Options
|
385 |
|
386 | ##### spacing
|
387 |
|
388 | Type: `Number`
|
389 |
|
390 | Default: `2`
|
391 |
|
392 | ### XML
|
393 |
|
394 | Return an unformatted XML valid representation of the todos.
|
395 |
|
396 | Parsed using [json2xml](https://github.com/estheban/node-json2xml)
|
397 |
|
398 | #### Options
|
399 |
|
400 | ##### header
|
401 |
|
402 | Whether to include xml header
|
403 |
|
404 | Type: `Boolean`
|
405 |
|
406 | Default: `true`
|
407 |
|
408 | ##### attributes_key
|
409 |
|
410 | See https://github.com/estheban/node-json2xml#options--behaviour
|
411 |
|
412 | Type: `Boolean`
|
413 |
|
414 | Default: `undefined`
|
415 |
|
416 | ## License
|
417 |
|
418 | MIT ©[Gilad Peleg](http://giladpeleg.com)
|