Skip to content

Commit 9847344

Browse files
author
Stephen Mathieson
committed
0.1.2: filters support
1 parent 09bebdd commit 9847344

File tree

6 files changed

+76
-13
lines changed

6 files changed

+76
-13
lines changed

lib/cli.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ var commander = require('commander');
44

55
var cpplint = require('./index.js');
66

7+
var filters = require('./filters.js');
8+
79
var reporters = require('./reporters/index.js');
810

911
var cli = commander
1012
.option('-v, --verbose [verbosity]', 'Set the verbosity level', Number, 1)
1113
.option('-r, --reporter [reporter]', 'Set the reporter', String, 'spec')
14+
.option('-filters, --filters [filters]', 'Set a list of ignored errors')
1215
.parse(process.argv);
1316

1417
var options = {};
@@ -30,7 +33,13 @@ if (!options.reporter) {
3033
// set the verbosity level
3134
options.verbosity = cli.verbose;
3235

33-
// set the remainging options (assume we should lint them)
36+
// set the ignored errors
37+
if (cli.filters) {
38+
options.filters = filters.parse(cli.filters);
39+
}
40+
41+
// set the remainging options (assume they're files and we should lint them)
3442
options.files = cli.args;
3543

44+
// run this thingy
3645
cpplint(options, options.reporter);

lib/make-args.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ function filter(filters) {
7272

7373
return '--filter=' + result;
7474
}
75+
/*
76+
function filter(excluded) {
77+
'use strict';
78+
79+
var index, length, exclude,
80+
parts, category, subcategory,
81+
result = '';
82+
83+
for (index = 0, length = excluded.length; index < length; index += 1) {
84+
85+
exclude = excluded[index];
86+
87+
parts = exclude.split('-');
88+
category = parts[0];
89+
subcategory = parts[1];
90+
91+
result += '-' + category + '/' + subcategory;
92+
93+
}
94+
95+
return '--filter=';
96+
}
97+
*/
7598

7699
/**
77100
* Get arguments for cpplint

lib/parse-options.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ var MIN_VERBOSITY = 0;
2323
var defaults = {};
2424
defaults.verbosity = 1;
2525
defaults.counting = 'total';
26-
26+
defaults.filters = require('./filters.js').defaults;
2727

2828
/**
29-
* [parseOptions description]
30-
*
3129
* @async
3230
* @param {Object} options
3331
* @param {Function} next
3432
*/
3533
function parseOptions(options, next) {
3634
'use strict';
3735

38-
var conf = extend(defaults, options);
36+
var conf = extend(defaults, options, true);
3937

4038
if (!conf.files || !conf.files.length) {
4139
return next(new Error('must provide some files'));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"description": "Validates C++ files with cpplint",
55

6-
"version": "0.1.1",
6+
"version": "0.1.2",
77

88
"homepage": "https://github.com/stephenmathieson/node-cpplint",
99

readme.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ line, and to be used as a Grunt task.
99

1010
### Options
1111

12-
All methods of using this module allow for three specific configuration options:
12+
All methods of using this module allow for four specific configuration options:
1313

1414
- **reporter** The reporter to use ( *spec* | *json* | *plain-text* ); defaults
1515
to *spec*.
@@ -20,16 +20,33 @@ is provided, then the count of errors in each of the top-level categories like
2020
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.
23+
- **filters** Enable/disable filtering for specific errors.
24+
2325

2426
A list of files is also expected.
2527

2628

2729
### CLI usage
2830

31+
Using the `spec` reporter, disabling *whitespace/braces* errors and linting *file1*.
32+
33+
```bash
34+
bin/cpplint --reporter spec --filter whitespace-braces file1
35+
```
36+
37+
Setting verbosity to `3` and the counting-type to `detailed` while linting *file1* and *file2*.
38+
2939
```bash
30-
bin/cpplint --verbose (1-5) --reporter (spec|json|plain-text) --counting (total|toplevel|detailed) file1 file2 ...
40+
bin/cpplint --verbose 3 --counting detailed file2 file3
3141
```
3242

43+
Using the `plain-text` reporter, ignoring *build/deprecated* errors and linting *file1*.
44+
45+
```bash
46+
bin/cpplint --filter build-deprecated --reporter plain-text
47+
```
48+
49+
3350
### JavaScript usage
3451

3552
Using the `spec` reporter
@@ -46,14 +63,20 @@ var options = {
4663
cpplint(options, reporter);
4764
```
4865

49-
Using a custom reporter
66+
Using a custom reporter, disabling *whitespace/braces* and enabling *whitespace/include_alpha*
5067

5168
```javascript
5269
var cpplint = require('lib/index');
5370
var options = {
5471
files: [
5572
'/path/to/some/files.cc'
56-
]
73+
],
74+
filters: {
75+
'whitespace': {
76+
'braces': false,
77+
'include_alpha': true
78+
}
79+
}
5780
};
5881

5982
cpplint(options, function (err, report) {
@@ -64,6 +87,8 @@ cpplint(options, function (err, report) {
6487
### Grunt Task
6588

6689
```javascript
90+
grunt.loadNpmTasks('node-cpplint');
91+
6792
grunt.initConfig({
6893
cpplint: {
6994
files: [
@@ -72,6 +97,12 @@ grunt.initConfig({
7297
],
7398
reporter: 'spec',
7499
verbosity: 1
100+
},
101+
filters: {
102+
'whitespace': {
103+
'braces': false,
104+
'include_alpha': true
105+
}
75106
}
76107
});
77108
```
@@ -80,8 +111,7 @@ grunt.initConfig({
80111

81112
Future plans (in no perticular order):
82113
- better test coverage
83-
- support for `filters`
84-
- JUnit-xml reporter
114+
- xunit-xml reporter
85115

86116

87117
## Contributing
@@ -93,6 +123,9 @@ and verify that all unit tests are passing with `grunt vows`.
93123

94124
## Revision History
95125

126+
### 0.1.2
127+
- added support for ignoring certain errors (filters)
128+
96129
### 0.1.1
97130
- added simple grunt task
98131

test/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,4 @@ suite.addBatch({
178178
});
179179

180180

181-
suite.export(module);
181+
suite.export(module);

0 commit comments

Comments
 (0)