Skip to content

Commit d9c6bb0

Browse files
committed
complete re-write of the main fork
1 parent 1a8c87b commit d9c6bb0

11 files changed

+569
-430
lines changed

.gitignore

+44-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
node_modules
1+
# Logs
2+
logs
3+
*.log
4+
5+
npm-debug.log*
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# node-waf configuration
22+
.lock-wscript
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directory
28+
node_modules/
29+
30+
# Users Environment Variables
31+
.lock-wscript
32+
33+
cache
34+
35+
# Optional npm cache directory
36+
.npm
37+
38+
# Optional REPL history
39+
.node_repl_history
40+
41+
# sonar relevant files
42+
.sonar
43+
44+
coverage/

.notesrc

-2
This file was deleted.

Cakefile

-14
This file was deleted.

README.md

+149-20
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,163 @@
1-
node-notes is a node.js version of Rails' "rake notes" functionality. It allows you
2-
to put comments in your code and then have them annotated across your whole project. Uses local ``.gitignore`` to ignore files or default ignore list.
1+
code-notes is a node.js version of Rails' "rake notes" functionality. It allows you to put comments in your code and then have them annotated across your whole project.
2+
3+
code-notes is based on two npm modules, mainly forked from [fixme](https://github.com/JohnPostlethwait/fixme) but also inspired by [node-notes](https://github.com/stephenb/node-notes). The main differences in this module is:
4+
5+
- Flexibility in defining the source scanning directory
6+
- The ability to pass exclude patterns that are compatible with [multimatch](https://github.com/sindresorhus/multimatch)
7+
- The ability to read exclusion list from a `.gitignore` file
8+
9+
It ends up giving you an output like this:
10+
11+
![](http://i.imgur.com/OXsTtCZ.png)
312

413
### Installation:
514

6-
npm install notes -g
15+
npm install code-notes -g
16+
17+
### CLI Usage ###
18+
19+
```sh
20+
notes --help
21+
```
22+
23+
### Options:
24+
25+
```
26+
Usage: notes [options]
27+
28+
Tool to summarise all code annotation like TODO or FIXME
29+
30+
Options:
31+
32+
-h, --help output usage information
33+
-V, --version output the version number
34+
-s, --source [dir] root directory to be included only for checks (default: current working directory)
35+
-x, --patterns [dir] Path patterns to exclude (default: include all files and directories)
36+
-e, --encoding [type] file encoding to be scanned (default: utf8)
37+
-l, --line-length <n> number of max characters a line (default: 1000)
38+
-h, --ignore-hidden <n> ignore hidden files (default: false)
39+
-g, --git-ignore <n> ignore patterns from your .gitignore file. This paramter accepts the path for the .gitIgnore file (default: false | no .gitignore is read
40+
```
41+
42+
### Configure Options (In More Detail)
43+
44+
* **source:** The path to scan through for notes, defaults to process.cwd()
45+
* **patterns:** Glob patterns for files directories to ignore. Passes these straight to [multimatch](https://github.com/sindresorhus/multimatch) so check there for more information on proper syntax.
46+
* **ignoreHidden:** Define if you want to ignore hidden files and directories. Defaults to true as all paths will be scanned.
47+
* **encoding:** The encoding the files scanned will be opened as.
48+
* **lineLength:** The number of max characters a line can be before Fixme gives up and doen not scan it for matches. If a line is too long, the regular expression will take an extremely long time to finish. *You have been warned!*
49+
* **gitIgnore**: Path to your `.gitignore` file. The exclusion patterns will be automatically read from there and merged with your defined patterns if found.
50+
51+
### Deep dive into patterns
52+
53+
#### Globbing patterns
54+
55+
- `*` matches any number of characters, but not `/`
56+
- `?` matches a single character, but not `/`
57+
- `**` matches any number of characters, including `/`, as long as it's the only thing in a path part
58+
- `{}` allows for a comma-separated list of "or" expressions
59+
60+
Note that you are defining exclusion patterns, no need to add the negation operator `!` in front of each pattern as it will be added automatically.
61+
62+
#### Directories exclusion
63+
64+
An important thing to take into consideration when defining exclusion patterns for directories is that you need to make sure to append a trailing backslash `/` to the directory path. For example:
65+
66+
```bash
67+
# Exclude node_modules
68+
notes -x node_modules/
769

8-
### Usage:
70+
# Exclude folder `src/lib`
71+
notes -x src/lib/
72+
```
973

10-
$ notes # will search for notes in cwd
11-
$ notes . # will search for notes in cwd considers .gitignore to ignore files
12-
$ notes lib/ test/ # will search only in lib and test
74+
> This pattern should also be followed inside of your `.gitignore` file, so make sure you edit that accordingly
1375
1476
### What It Does:
1577

1678
For example, if a file contained these lines somewhere in it:
1779

18-
code...
19-
# NOTE: This line should get annoated by Notes.
20-
# OPTIMIZE Make things faster!
80+
```
81+
// NOTE: This is the sample output for a note!
82+
// OPTIMIZE (John Postlethwait): This is the sample output for an optimize with an author!
83+
// TODO: This is the sample output for a todo!
84+
// HACK: This is the sample output for a hack! Don't commit hacks!
85+
// XXX: This is the sample output for a XXX! XXX's need attention too!
86+
// FIXME (John Postlethwait): This is the sample output for a fixme! Seriously fix this...
87+
// BUG: This is the sample output for a bug! Who checked in a bug?!
88+
```
2189

22-
more code...
23-
# TODO: Annotate your tasks.
90+
Those comments would be annotated as:
2491

25-
yet more code...
26-
# FIXME: Keep up with things to fix.
92+
```
93+
• path/to/your/directory/file.js [7 messages]:
94+
[Line 1] ✐ NOTE: This is here because sometimes an intermittent issue appears.
95+
[Line 7] ↻ OPTIMIZE: This could be reworked to not do a O(N2) lookup.
96+
[Line 9] ✓ TODO from John: Add a check here to ensure these are always strings.
97+
[Line 24] ✄ HACK: I am doing something here that is horrible, but it works for now...
98+
[Line 89] ✗ XXX: Let's do this better next time? It's bad.
99+
[Line 136] ☠ FIXME: We sometimes get an undefined index in this array.
100+
[Line 211] ☢ BUG: If the user inputs "Easter" we always output "Egg", even if they wanted a "Bunny".
101+
```
27102

28-
Those comments would be annotated as:
103+
### Example Usage
104+
105+
```bash
106+
107+
# Exclude any pattern inside of .gitignore file in the same path as the script is run and ignore any hidden files and folders
108+
notes -g .gitignore -h true
109+
# Exclude any file under the src directory and node_modules and any file with .md extension
110+
notes -x src/ -x -x node_modules/ -x *.md
111+
```
112+
113+
### Extending code-notes
114+
115+
code-notes scan for NOTE, OPTIMIZE, TODO, HACK, XXX, FIXME, and BUG comments within your source, and print them to stdout so you can deal with them. However, if you wish to define more annotations to be extracted, this can be easily done by extending the definitions in `lib/messageChecks.js`. An example for an annotation:
116+
117+
```javascript
118+
todo: {
119+
regex: /[\/\/][\/\*]\s*TODO\s*(?:\(([^:]*)\))*\s*:?\s*(.*)/i,
120+
label: ' ✓ TODO',
121+
colorer: chalk.magenta
122+
}
123+
```
124+
125+
#### Ignoring files
126+
127+
Certain file extensions are skipped from being scanned. They are defined in `lib/notes.js`
128+
129+
```javascript
130+
const BAD_EXTENSIONS = ["!*.jpg", "!*.jpeg", "!*.mov", "!*.mp3", "!*.gif", "!*.png", "!*.log", "!*.bin", "!*.psd", "!*.swf", "!*.fla", "!*.ico"];
131+
```
132+
133+
The object should contain the following fields:
134+
135+
- `regex`: this is used to extract the line containing the annotation
136+
- `label`: this defines what will be printed in the console
137+
- `colorer`: this controls the visual display of the message and can be customised with any valid [chalk](https://www.npmjs.com/package/chalk) option
138+
139+
140+
### Writing Comments for Use With Fixme ###
141+
142+
A code annotation needs to follow these rules to be picked up by Fixme:
143+
144+
* Can be preceeded by 0 to n number of characters, this includes the comment characters // and /*
145+
* Must have one of the words: NOTE, OPTIMIZE, TODO, HACK, XXX, FIXME, or BUG
146+
* Can have 0 to n space characters
147+
* Can have an author in parenthesis after the above word, and before a colon (:)
148+
* Can have 0 to n space characters
149+
* Must be followed by a colon (:)
150+
* Can have 0 to n space characters
151+
* Should have a message of 0 to n characters for the note
152+
153+
#### Displaying Authors ####
154+
155+
You can have an author of a comment displayed via Fixme:
156+
157+
```javascript
158+
// NOTE(John Postlethwait): This comment will be shown as a note, and have an author!
159+
```
29160

30-
* /path/to/my/file
31-
Line 8: ✐ NOTE This line should get annoated by Notes.
32-
Line 9: ↘ OPTIMIZE Make things faster!
33-
Line 10: ✓ TODO Annotate your tasks.
34-
Line 11: ☂ FIXME Keep up with things to fix.
161+
```shell
162+
[Line 1] ✐ NOTE from John Postlethwait: This comment will be shown as a note, and have an author!
163+
```

bin/notes

+15-42
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,22 @@
11
#!/usr/bin/env node
22

3-
/**
4-
* Core dependencies.
5-
*/
6-
var fs = require('fs');
7-
var path = require('path');
3+
"use strict";
84

9-
/**
10-
* Notes.
11-
*
12-
* @type {Function}
13-
*/
14-
var Notes = require('../lib/notes');
5+
const program = require('commander');
156

16-
/**
17-
* Argv.
18-
*
19-
* @type {Array}
20-
*/
21-
var argv = process.argv.slice(2, process.argv.length);
7+
const Notes = require('../lib/notes');
228

23-
/**
24-
* Current working directory.
25-
*
26-
* @type {String}
27-
*/
28-
var cwd = process.cwd();
9+
program
10+
.version('1.0.0')
11+
.description('Tool to summarise all code annotation like TODO or FIXME')
12+
.option('-s, --source [dir]', 'root directory to be included only for checks (default: current working directory)')
13+
.option('-x, --patterns [dir]', 'Path patterns to exclude (default: include all files and directories)',
14+
function collect(val, collector) { collector.push("" + val); return collector; }, [])
15+
.option('-e, --encoding [type]', 'file encoding to be scanned (default: utf8)')
16+
.option('-l, --line-length <n>', 'number of max characters a line (default: 1000)', parseInt)
17+
.option('-h, --ignore-hidden <n>', 'ignore hidden files (default: false)')
18+
.option('-g, --git-ignore <n>', 'ignore patterns from your .gitignore file. This paramter accepts the path for the .gitIgnore file (default: false | no .gitignore is read')
2919

30-
/**
31-
* Runtime configurations path.
32-
*
33-
* @type {String}
34-
*/
35-
var rc = path.join(cwd, '.notesrc');
20+
.parse(process.argv);
3621

37-
if (0 !== argv.length) {
38-
return argv.forEach(function(arg) {
39-
new Notes(arg).annotate();
40-
});
41-
}
42-
43-
if (!fs.existsSync(rc)) {
44-
return new Notes(cwd).annotate();
45-
}
46-
47-
fs.readFileSync(rc, 'utf8').trim().split(/\s+/).forEach(function(directory) {
48-
new Notes(directory).annotate();
49-
});
22+
Notes(program);

lib/filter.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const multimatch = require('multimatch');
4+
5+
6+
let ignoreHidden, patterns;
7+
8+
class Filter {
9+
10+
constructor(_ignoreHidden, _patterns) {
11+
ignoreHidden = _ignoreHidden;
12+
patterns = _patterns;
13+
}
14+
15+
/**
16+
* Determines whether or not to let the file through. by ensuring that the
17+
* file name does not match one of the excluded directories, and ensuring it
18+
* matches one of the file filters.
19+
*
20+
* It will also ensure that even if a binary file matches the filter patterns,
21+
* it will not let it through as searching binary file contents for string
22+
* matches will never make sense.
23+
*
24+
* @param {String} fileInformation
25+
*
26+
* @return {Boolean}
27+
*/
28+
fileFilterer(fileInformation) {
29+
let matchOptions = {};
30+
if (!ignoreHidden) matchOptions["dot"] = true;
31+
return multimatch(fileInformation.path, patterns, matchOptions).length;
32+
}
33+
}
34+
module.exports = Filter;

0 commit comments

Comments
 (0)