This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var assert = require('assert'); | ||
|
||
module.exports = function() {}; | ||
|
||
module.exports.prototype = { | ||
configure: function(disallowCapitalizedComments) { | ||
assert( | ||
disallowCapitalizedComments === true, | ||
'disallowCapitalizedComments option requires a value of true or should be removed' | ||
); | ||
}, | ||
|
||
getOptionName: function() { | ||
return 'disallowCapitalizedComments'; | ||
}, | ||
|
||
check: function(file, errors) { | ||
var lowerCasePattern = /[a-z]/; | ||
var alphabeticalPattern = /[a-z|A-Z]/; | ||
var _this = this; | ||
|
||
file.getComments().forEach(function(comment) { | ||
var stripped = comment.value.replace(/[\n\s\*]/g, ''); | ||
var firstChar = stripped[0]; | ||
|
||
if (alphabeticalPattern.test(firstChar) && !lowerCasePattern.test(firstChar)) { | ||
errors.add( | ||
'Comments must start with a lowercase letter', | ||
comment.loc.start | ||
); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var assert = require('assert'); | ||
|
||
module.exports = function() {}; | ||
|
||
module.exports.prototype = { | ||
configure: function(requireCapitalizedComments) { | ||
assert( | ||
requireCapitalizedComments === true, | ||
'requireCapitalizedComments option requires a value of true or should be removed' | ||
); | ||
}, | ||
|
||
getOptionName: function() { | ||
return 'requireCapitalizedComments'; | ||
}, | ||
|
||
check: function(file, errors) { | ||
var upperCasePattern = /[A-Z]/; | ||
var alphabeticalPattern = /[a-z|A-Z]/; | ||
var _this = this; | ||
|
||
file.getComments().forEach(function(comment) { | ||
var stripped = comment.value.replace(/[\n\s\*]/g, ''); | ||
var firstChar = stripped[0]; | ||
|
||
if (alphabeticalPattern.test(firstChar) && !upperCasePattern.test(firstChar)) { | ||
errors.add( | ||
'Comments must start with an uppercase letter', | ||
comment.loc.start | ||
); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var Checker = require('../../lib/checker'); | ||
var assert = require('assert'); | ||
|
||
describe('rules/disallow-capitalized-comments', function() { | ||
var checker; | ||
|
||
beforeEach(function() { | ||
checker = new Checker(); | ||
checker.registerDefaultRules(); | ||
checker.configure({ disallowCapitalizedComments: true }); | ||
}); | ||
|
||
it('should report on an uppercase start of a comment', function() { | ||
assert(checker.checkString('//Invalid').getErrorCount() === 1); | ||
assert(checker.checkString('// Invalid').getErrorCount() === 1); | ||
assert(checker.checkString('/** Invalid */').getErrorCount() === 1); | ||
assert(checker.checkString('/**\n * Invalid\n */').getErrorCount() === 1); | ||
assert(checker.checkString('/* Invalid */').getErrorCount() === 1); | ||
assert(checker.checkString('/*\n Invalid\n */').getErrorCount() === 1); | ||
}); | ||
|
||
it('should not report on a lowercase start of a comment', function() { | ||
assert(checker.checkString('//valid').isEmpty()); | ||
assert(checker.checkString('// valid').isEmpty()); | ||
assert(checker.checkString('/** valid */').isEmpty()); | ||
}); | ||
|
||
it('should not report on comments that start with a non-alphabetical character', function() { | ||
assert(checker.checkString('//123').isEmpty()); | ||
assert(checker.checkString('// 123').isEmpty()); | ||
assert(checker.checkString('/**123*/').isEmpty()); | ||
assert(checker.checkString('/**\n @todo: foobar\n */').isEmpty()); | ||
assert(checker.checkString('/** 123*/').isEmpty()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var Checker = require('../../lib/checker'); | ||
var assert = require('assert'); | ||
|
||
describe('rules/require-capitalized-comments', function() { | ||
var checker; | ||
|
||
beforeEach(function() { | ||
checker = new Checker(); | ||
checker.registerDefaultRules(); | ||
checker.configure({ requireCapitalizedComments: true }); | ||
}); | ||
|
||
it('should report on a lowercase start of a comment', function() { | ||
assert(checker.checkString('//invalid').getErrorCount() === 1); | ||
assert(checker.checkString('// invalid').getErrorCount() === 1); | ||
assert(checker.checkString('/** invalid */').getErrorCount() === 1); | ||
assert(checker.checkString('/* invalid */').getErrorCount() === 1); | ||
assert(checker.checkString('/**\n * invalid\n*/').getErrorCount() === 1); | ||
}); | ||
|
||
it('should not report an uppercase start of a comment', function() { | ||
assert(checker.checkString('//Valid').isEmpty()); | ||
assert(checker.checkString('// Valid').isEmpty()); | ||
assert(checker.checkString('/** Valid */').isEmpty()); | ||
}); | ||
|
||
it('should not report on comments that start with a non-alphabetical character', function() { | ||
assert(checker.checkString('//123').isEmpty()); | ||
assert(checker.checkString('// 123').isEmpty()); | ||
assert(checker.checkString('/**123*/').isEmpty()); | ||
assert(checker.checkString('/**\n @todo: foobar\n */').isEmpty()); | ||
assert(checker.checkString('/** 123*/').isEmpty()); | ||
}); | ||
}); |