Skip to content

Commit bc1288c

Browse files
committed
Merge branch 'exposing-extensions-arg'
2 parents c60d899 + e7ea8dd commit bc1288c

File tree

6 files changed

+70
-9
lines changed

6 files changed

+70
-9
lines changed

lib/cli.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var cli = commander
1212
.option('-v, --verbose [verbosity]', 'Set the verbosity level', Number, 1)
1313
.option('-r, --reporter [reporter]', 'Set the reporter', String, 'spec')
1414
.option('-filters, --filters [filters]', 'Set a list of ignored errors')
15+
.option('-extensions, --extensions [extensions]', 'Set The allowed file extensions that cpplint will check')
1516
.parse(process.argv);
1617

1718
var options = {};
@@ -38,6 +39,11 @@ if (cli.filters) {
3839
options.filters = filters.parse(cli.filters);
3940
}
4041

42+
// set the ignored errors
43+
if (cli.extensions) {
44+
options.extensions = cli.extensions;
45+
}
46+
4147
// set the remainging options (assume they're files and we should lint them)
4248
options.files = cli.args;
4349

lib/make-args.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ function counting(type) {
2626
return '--counting=' + type;
2727
}
2828

29+
/**
30+
* Get the cpplint `extensions` argument
31+
*
32+
* @param {String|Array} exts
33+
* @return {String}
34+
*/
35+
function extensions(exts) {
36+
var extsType = {}.toString.call(exts);
37+
if (extsType === '[object Array]') {
38+
exts = exts.join(',');
39+
}
40+
return '--extensions=' + exts;
41+
}
42+
2943
/**
3044
* Get the cpplint `filter` argument
3145
*
@@ -109,6 +123,11 @@ function makeArgs(conf, next) {
109123
args.push(filter(conf.filters));
110124
}
111125

126+
if (conf.extensions) {
127+
// set filters
128+
args.push(extensions(conf.extensions));
129+
}
130+
112131
// set files
113132
args.push(conf.files.join(' '));
114133

@@ -123,5 +142,6 @@ module.exports = {
123142
'makeArgs': makeArgs,
124143
'filter': filter,
125144
'counting': counting,
126-
'verbosity': verbosity
145+
'verbosity': verbosity,
146+
'extensions': extensions
127147
};

lib/parse-output.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ var expressions = {
77
// Done processing /Users/stephenmathieson/work/node-cpplint/test/fixtures/somefile.cc
88
'done': {
99
'is': /Done processing [\/a-z\-\_\.\d]+/i,
10-
'file': / ([\/a-z\-\_\.\d]+)$/i
10+
'file': / ([\/a-z\-\_\.\d\+]+)$/i
1111
},
1212
// /Users/stephenmathieson/work/node-cpplint/test/fixtures/somefile.cc:302: Blank line at the end of a code block. Is this needed? [whitespace/blank_line] [3]
1313
'error': {
14-
'is': /[\/a-z-_\.]+\:[\d]+\:[ ]{2}.*\[[1-5]\]/i
14+
'is': /[\/a-z-_\.\+]+\:[\d]+\:[ ]{2}.*\[[1-5]\]/i
1515
}
1616
};
1717

readme.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ a count is provided for each category like `build/class`.
2121
- **verbose** The verbosity level; defaults to *1*. A number *0-5* to restrict
2222
errors to certain verbosity levels.
2323
- **filters** Enable/disable filtering for specific errors.
24+
- **extensions** List of file extensions to lint.
2425

2526

2627
A list of files is also expected.
@@ -43,9 +44,14 @@ bin/cpplint --verbose 3 --counting detailed file2 file3
4344
Using the `plain-text` reporter, ignoring *build/deprecated* errors and linting *file1*.
4445

4546
```bash
46-
bin/cpplint --filter build-deprecated --reporter plain-text
47+
bin/cpplint --filter build-deprecated --reporter plain-text file1
4748
```
4849

50+
Using the `cc` and `hpp` extensions and linting *source1.cc* and *source1.hpp*.
51+
52+
```bash
53+
bin/cpplint --extensions cc,hpp source1.cc source1.hpp
54+
```
4955

5056
### JavaScript usage
5157

@@ -76,7 +82,12 @@ var options = {
7682
'braces': false,
7783
'include_alpha': true
7884
}
79-
}
85+
},
86+
// This could be an array of strings or a comma separated string
87+
extensions: [
88+
'cc',
89+
'hpp'
90+
]
8091
};
8192

8293
cpplint(options, function (err, report) {
@@ -103,7 +114,12 @@ grunt.initConfig({
103114
'braces': false,
104115
'include_alpha': true
105116
}
106-
}
117+
},
118+
// This could be an array of strings or a comma separated string
119+
extensions: [
120+
'cc',
121+
'hpp'
122+
]
107123
});
108124
```
109125

tasks/cpplint.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ module.exports = function (grunt) {
3535

3636
options.filters = extend(filters.defaults, gruntFilters, true);
3737

38+
options.extensions = conf('extensions');
39+
3840
options.files = grunt.file.expand(conf('files'));
3941
options.verbosity = conf('verbosity') || 1;
4042
options.counting = conf('counting') || 'toplevel';

test/make-args.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ suite.addBatch({
8888
'subcat5': false,
8989
'subcat6': true
9090
}
91-
}
91+
},
92+
'extensions': [
93+
'cpp',
94+
'cc',
95+
'xx'
96+
]
9297
}),
9398
'should set correct verbosity level': function (err, args) {
9499
assert.includes(args, '--verbose=1');
@@ -101,10 +106,13 @@ suite.addBatch({
101106
},
102107
'should pass the correct filters': function (err, args) {
103108
assert.includes(args, '--filter=+category1/subcat1,-category1/subcat2,+category1/subcat3,+category2/subcat1,-category2/subcat2,+category2/subcat3,+category2/subcat4,-category2/subcat5,+category2/subcat6');
109+
},
110+
'should pass the correct extensions': function (err, args) {
111+
assert.includes(args, '--extensions=cpp,cc,xx');
104112
}
105113

106114
},
107-
'values (without filters)': {
115+
'values (without filters or extensions)': {
108116
topic: makeArgs({
109117
'verbosity': 1,
110118
'counting': 'total',
@@ -127,7 +135,16 @@ suite.addBatch({
127135
assert.includes(args, '/path/to/file1 /path/to/file2');
128136
},
129137
'should not pass a filter value': function (err, args) {
130-
assert.equal(args.length, 4); // not quite good enough...
138+
var i;
139+
for (i = 0; i < args.length; i += 1) {
140+
assert.isFalse(args[i].indexOf('filter') !== -1, 'filter was in the list of arguments');
141+
}
142+
},
143+
'should not pass an extensions value': function (err, args) {
144+
var i;
145+
for (i = 0; i < args.length; i += 1) {
146+
assert.isFalse(args[i].indexOf('extensions') !== -1, 'extensions was in the list of arguments');
147+
}
131148
}
132149
}
133150
});

0 commit comments

Comments
 (0)