Skip to content

Commit f35c0eb

Browse files
committed
Added extensions option for non-cli uses
1 parent 719bc46 commit f35c0eb

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

lib/make-args.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ function counting(type) {
2929
/**
3030
* Get the cpplint `extensions` argument
3131
*
32-
* @param {String} type
32+
* @param {String|Array} exts
3333
* @return {String}
3434
*/
3535
function extensions(exts) {
36+
var extsType = {}.toString.call(exts);
37+
if (extsType === '[object Array]') {
38+
exts = exts.join(',');
39+
}
3640
return '--extensions=' + exts;
3741
}
3842

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: 9 additions & 1 deletion
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,6 +106,9 @@ 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
},

0 commit comments

Comments
 (0)