Skip to content

Commit 3ce37db

Browse files
author
Arkadiy Tetelman
committed
Add support for --linelength option
1 parent eafcb97 commit 3ce37db

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

lib/cli.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var cli = commander
1313
.option('-r, --reporter [reporter]', 'Set the reporter', String, 'spec')
1414
.option('-filters, --filters [filters]', 'Set a list of ignored errors')
1515
.option('-extensions, --extensions [extensions]', 'Set The allowed file extensions that cpplint will check')
16+
.option('-l, --linelength [linelength]', 'Set the allowed line length', Number)
1617
.parse(process.argv);
1718

1819
var options = {};
@@ -39,11 +40,16 @@ if (cli.filters) {
3940
options.filters = filters.parse(cli.filters);
4041
}
4142

42-
// set the ignored errors
43+
// set the extensions
4344
if (cli.extensions) {
4445
options.extensions = cli.extensions;
4546
}
4647

48+
// set the linelength
49+
if (cli.linelength) {
50+
options.linelength = cli.linelength;
51+
}
52+
4753
// set the remainging options (assume they're files and we should lint them)
4854
options.files = cli.args;
4955

lib/make-args.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ function extensions(exts) {
4040
return '--extensions=' + exts;
4141
}
4242

43+
/**
44+
* Get the cpplint `linelength` argument
45+
*
46+
* @param {Number} length
47+
* @return {String}
48+
*/
49+
function linelength(length) {
50+
return '--linelength=' + length;
51+
}
52+
4353
/**
4454
* Get the cpplint `filter` argument
4555
*
@@ -128,6 +138,11 @@ function makeArgs(conf, next) {
128138
args.push(extensions(conf.extensions));
129139
}
130140

141+
//set linelength
142+
if (conf.linelength) {
143+
args.push(linelength(conf.linelength));
144+
}
145+
131146
// set files
132147
args.push(conf.files.join(' '));
133148

@@ -140,6 +155,7 @@ function makeArgs(conf, next) {
140155

141156
module.exports = {
142157
'makeArgs': makeArgs,
158+
'linelength': linelength,
143159
'filter': filter,
144160
'counting': counting,
145161
'verbosity': verbosity,

readme.md

Lines changed: 5 additions & 7 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 four specific configuration options:
12+
All methods of using this module allow for these specific configuration options:
1313

1414
- **reporter** The reporter to use ( *spec* | *json* | *plain-text* ); defaults
1515
to *spec*.
@@ -22,11 +22,10 @@ a count is provided for each category like `build/class`.
2222
errors to certain verbosity levels.
2323
- **filters** Enable/disable filtering for specific errors.
2424
- **extensions** List of file extensions to lint.
25-
25+
- **linelength** The allowed line length.
2626

2727
A list of files is also expected.
2828

29-
3029
### CLI usage
3130

3231
Using the `spec` reporter, disabling *whitespace/braces* errors and linting *file1*.
@@ -35,10 +34,10 @@ Using the `spec` reporter, disabling *whitespace/braces* errors and linting *fil
3534
bin/cpplint --reporter spec --filter whitespace-braces file1
3635
```
3736

38-
Setting verbosity to `3` and the counting-type to `detailed` while linting *file1* and *file2*.
37+
Setting verbosity to `3`, line length to `120`, and the counting-type to `detailed` while linting *file1* and *file2*.
3938

4039
```bash
41-
bin/cpplint --verbose 3 --counting detailed file2 file3
40+
bin/cpplint --verbose 3 --counting detailed --linelength 120 file2 file3
4241
```
4342

4443
Using the `plain-text` reporter, ignoring *build/deprecated* errors and linting *file1*.
@@ -115,6 +114,7 @@ grunt.initConfig({
115114
'include_alpha': true
116115
}
117116
},
117+
linelength: 120,
118118
// This could be an array of strings or a comma separated string
119119
extensions: [
120120
'cc',
@@ -129,7 +129,6 @@ Future plans (in no particular order):
129129
- better test coverage
130130
- xunit-xml reporter
131131

132-
133132
## Contributing
134133

135134
In lieu of a formal styleguide, take care to maintain the existing coding
@@ -168,7 +167,6 @@ and verify that all unit tests are passing with `grunt vows`.
168167
### 0.1.1
169168
- added simple grunt task
170169

171-
172170
### 0.1.0
173171

174172
- first public version

tasks/cpplint.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = function (grunt) {
4040
options.files = grunt.file.expand(conf('files'));
4141
options.verbosity = conf('verbosity') || 1;
4242
options.counting = conf('counting') || 'toplevel';
43+
options.linelength = conf('linelength');
4344

4445
cpplint(options, function (err, report) {
4546

test/make-args.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ suite.addBatch({
9292
'cpp',
9393
'cc',
9494
'xx'
95-
]
95+
],
96+
'linelength': 120
9697
}),
9798
'should set correct verbosity level': function (err, args) {
9899
assert.includes(args, '--verbose=1');
@@ -108,6 +109,9 @@ suite.addBatch({
108109
},
109110
'should pass the correct extensions': function (err, args) {
110111
assert.includes(args, '--extensions=cpp,cc,xx');
112+
},
113+
'should pass the correct linelength': function (err, args) {
114+
assert.includes(args, '--linelength=120');
111115
}
112116

113117
},

0 commit comments

Comments
 (0)