Skip to content

Commit eb3b65d

Browse files
author
Stephen Mathieson
committed
adding the files
1 parent 5b2d89b commit eb3b65d

File tree

7 files changed

+373
-0
lines changed

7 files changed

+373
-0
lines changed

lib/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*jslint node:true*/
2+
3+
var runner = require('./runner.js');
4+
5+
var reporters = require('./reporters/index.js');
6+
7+
/**
8+
* [cpplint description]
9+
*
10+
* @async
11+
* @param {Object} options
12+
* @param {Function} reporter
13+
*/
14+
function cpplint(options, reporter) {
15+
'use strict';
16+
17+
return runner(options, reporter);
18+
}
19+
20+
module.exports = cpplint;
21+
22+
23+
cpplint({
24+
'files': [
25+
'/Users/stephenmathieson/work/amaze/signing/amaze-cpp-signing-extension-stephen/src/signing.cc',
26+
'/Users/stephenmathieson/work/amaze/signing/amaze-cpp-signing-extension-stephen/CPPSigningExtension.cc'
27+
]
28+
}, reporters.spec);

lib/lint-error.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*jslint node:true*/
2+
3+
require('colors');
4+
5+
var path = require('path');
6+
7+
var extend = require('./extend.js');
8+
9+
// [whitespace/blank_line] [3]
10+
var category = /\[([a-z]+)\/([a-z_]+)\] \[([1-5])\]/i;
11+
12+
function LintError(line) {
13+
'use strict';
14+
15+
var temp,
16+
parts = line.split(' ');
17+
18+
this.line = line;
19+
20+
// hack to handle reasons like this:
21+
// "Blank line at the end of a code block. Is this needed?"
22+
if (parts.length === 4) {
23+
temp = [];
24+
temp.push(parts[0]);
25+
temp.push([parts[1], parts[2]].join(' '));
26+
temp.push(parts[3]);
27+
parts = temp;
28+
}
29+
30+
temp = parts[0].split(':');
31+
this.file = temp[0];
32+
this.linenumber = temp[1];
33+
34+
this.reason = parts[1];
35+
36+
temp = parts[2].match(category);
37+
this.category = temp[1];
38+
this.sub_category = temp[2];
39+
this.level = temp[3];
40+
}
41+
42+
/**
43+
* @return {String} this.line
44+
*/
45+
LintError.prototype.toString = function () {
46+
'use strict';
47+
48+
return this.line;
49+
};
50+
51+
/**
52+
* Creates a plain Object based on properties of the LintError
53+
*
54+
* @return {Object}
55+
*/
56+
LintError.prototype.toObject = function () {
57+
'use strict';
58+
59+
var obj = extend({}, this);
60+
61+
return this;
62+
};
63+
64+
module.exports = LintError;

lib/make-args.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*jslint node:true*/
2+
3+
var path = require('path');
4+
5+
/*jslint nomen:true*/
6+
var CPPLINT = path.resolve(__dirname, '../cpplint/cpplint.py');
7+
/*jslint nomen:false*/
8+
9+
/**
10+
* [verbosity description]
11+
*
12+
* @param {String} type
13+
* @return {String}
14+
*/
15+
function verbosity(level) {
16+
'use strict';
17+
18+
return '--verbose=' + level.toString();
19+
}
20+
21+
/**
22+
* [counting description]
23+
*
24+
* @param {String} type
25+
* @return {String}
26+
*/
27+
function counting(type) {
28+
'use strict';
29+
30+
return '--counting=' + type;
31+
}
32+
33+
/**
34+
* [makeArgs description]
35+
*
36+
* @param {Object} conf
37+
* @param {Function} next
38+
* @return {Array}
39+
*/
40+
function makeArgs(conf, next) {
41+
'use strict';
42+
43+
var args = [ CPPLINT ];
44+
45+
args.push(verbosity(conf.verbosity));
46+
args.push(counting(conf.counting));
47+
48+
args.push(conf.files.join(' '));
49+
50+
if (typeof next === 'function') {
51+
return next(null, args);
52+
}
53+
54+
return args;
55+
}
56+
57+
module.exports = makeArgs;

lib/out.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*jslint node:true*/
2+
3+
/**
4+
* Output the given `str` to _stdout_ or the stream specified by `options`.
5+
*
6+
* Options:
7+
*
8+
* - `stream` defaulting to _stdout_
9+
*
10+
* Examples:
11+
*
12+
* mymodule.write('foo')
13+
* mymodule.write('foo', { stream: process.stderr })
14+
*
15+
*/
16+
function out(str, options) {
17+
18+
'use strict';
19+
20+
options = options || {};
21+
22+
(options.stream || process.stdout).write(str);
23+
24+
}
25+
26+
module.exports = out;

lib/parse-options.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*jslint node:true*/
2+
3+
var extend = require('./extend.js');
4+
5+
/**
6+
* Supported counting (`--counting=`) types
7+
* @type {Array}
8+
*/
9+
var COUNTING_TYPES = [
10+
'total',
11+
'toplevel',
12+
'detailed'
13+
];
14+
15+
// verbosity requirements
16+
var MAX_VERBOSITY = 5;
17+
var MIN_VERBOSITY = 0;
18+
19+
/**
20+
* The default _cpplint_ options
21+
* @type {Object}
22+
*/
23+
var defaults = {};
24+
defaults.verbosity = 1;
25+
defaults.counting = 'total';
26+
27+
28+
/**
29+
* [parseOptions description]
30+
*
31+
* @async
32+
* @param {Object} options
33+
* @param {Function} next
34+
*/
35+
function parseOptions(options, next) {
36+
'use strict';
37+
38+
var conf = extend(options, defaults);
39+
40+
if (!conf.files || !conf.files.length) {
41+
next(new Error('must provide some files'));
42+
}
43+
44+
if (conf.verbosity > MAX_VERBOSITY || conf.verbosity < MIN_VERBOSITY) {
45+
next(new Error('invalid verbosity level (0-5)'));
46+
}
47+
48+
if (COUNTING_TYPES.indexOf(conf.counting) === -1) {
49+
next(new Error('invalid counting type (' + COUNTING_TYPES.join(', ') + ')'));
50+
}
51+
52+
next(null, conf);
53+
}
54+
55+
module.exports.defaults = defaults;
56+
module.exports.parseOptions = parseOptions;

lib/parse-output.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*jslint node:true*/
2+
3+
var LintError = require('./lint-error.js');
4+
5+
/*jslint regexp:true*/
6+
var expressions = {
7+
// Done processing /Users/stephenmathieson/work/amaze/signing/amaze-cpp-signing-extension-stephen/CPPSigningExtension.cc
8+
'done': {
9+
'is': /Done processing [\/a-z\-\_\.\d]+/i,
10+
'file': / ([\/a-z\-\_\.\d]+)$/i
11+
},
12+
// /Users/stephenmathieson/work/amaze/signing/amaze-cpp-signing-extension-stephen/CPPSigningExtension.cc:302: Blank line at the end of a code block. Is this needed? [whitespace/blank_line] [3]
13+
'error': {
14+
'is': /[\/a-z-_\.]+\:[\d]+\:[ ]{2}.*\[[1-5]\]/i
15+
}
16+
};
17+
18+
/**
19+
* [parseOutput description]
20+
*
21+
* @param {String} output
22+
* @param {Function} next
23+
* @return {[type]}
24+
*/
25+
function parseOutput(output, next) {
26+
'use strict';
27+
28+
var errors = [], error,
29+
report = {},
30+
lines = output.split('\n').filter(function (line) {
31+
if (line) {
32+
return true;
33+
}
34+
35+
return false;
36+
});
37+
38+
lines.forEach(function (line) {
39+
40+
var filename;
41+
42+
if (line.match(expressions.done.is)) {
43+
44+
filename = line.match(expressions.done.file)[1];
45+
46+
if (!report.hasOwnProperty(filename)) {
47+
report[filename] = [];
48+
}
49+
50+
}
51+
52+
if (line.match(expressions.error.is)) {
53+
error = new LintError(line);
54+
filename = error.file;
55+
56+
if (!report.hasOwnProperty(filename)) {
57+
report[filename] = [];
58+
}
59+
60+
report[filename].push(error);
61+
62+
}
63+
64+
});
65+
66+
return next(null, report);
67+
//return next(null, errors);
68+
69+
}
70+
71+
module.exports = parseOutput;

lib/runner.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*jslint node:true*/
2+
3+
require('colors');
4+
5+
var spawn = require('child_process').spawn;
6+
7+
var exec = require('child_process').exec;
8+
9+
var parseOptions = require('./parse-options.js').parseOptions;
10+
11+
var makeArgs = require('./make-args.js');
12+
13+
var parseOutput = require('./parse-output.js');
14+
15+
function runner(options, next) {
16+
'use strict';
17+
18+
var cpplint;
19+
20+
parseOptions(options, function (err, config) {
21+
22+
if (err) {
23+
return next(err);
24+
}
25+
26+
var args = makeArgs(config);
27+
28+
cpplint = exec(args.join(' ').trim(), function (err, stdout, stderr) {
29+
30+
return parseOutput(stderr, next);
31+
32+
});
33+
34+
});
35+
36+
}
37+
38+
module.exports = runner;
39+
40+
/*
41+
42+
runner({
43+
'files': [
44+
'/Users/stephenmathieson/work/amaze/signing/amaze-cpp-signing-extension-stephen/src/signing.cc',
45+
'/Users/stephenmathieson/work/amaze/signing/amaze-cpp-signing-extension-stephen/CPPSigningExtension.cc'
46+
]
47+
}, function (err, report) {
48+
'use strict';
49+
50+
var files = Object.keys(report);
51+
52+
files.forEach(function (filename) {
53+
var errors = report[filename];
54+
55+
if (!errors.length) {
56+
console.log('PASS\t'.green + filename);
57+
58+
} else {
59+
console.log('FAIL\t'.red + filename + ' (' + errors.length.toString() + ')');
60+
61+
errors.forEach(function (error) {
62+
console.log(error.toString());
63+
});
64+
65+
}
66+
67+
});
68+
69+
});
70+
71+
*/

0 commit comments

Comments
 (0)