Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 9a72f4a

Browse files
AlexanderZeilmannmarkelog
authored andcommitted
requireCapitalizedComments: correct letter recognition
Fixes #842 Closes gh-847
1 parent 1d7d39d commit 9a72f4a

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

lib/rules/disallow-capitalized-comments.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
var assert = require('assert');
2+
var regenerate = require('regenerate');
3+
var Lu = require('unicode-6.3.0/categories/Lu/code-points');
4+
var Ll = require('unicode-6.3.0/categories/Ll/code-points');
5+
var Lt = require('unicode-6.3.0/categories/Lt/code-points');
6+
var Lm = require('unicode-6.3.0/categories/Lm/code-points');
7+
var Lo = require('unicode-6.3.0/categories/Lo/code-points');
8+
9+
var letterPattern = regenerate(Lu, Ll, Lt, Lm, Lo).toRegExp();
10+
var lowerCasePattern = regenerate(Ll).toRegExp();
211

312
module.exports = function() {};
413

@@ -15,14 +24,11 @@ module.exports.prototype = {
1524
},
1625

1726
check: function(file, errors) {
18-
var lowerCasePattern = /[a-z]/;
19-
var alphabeticalPattern = /[a-z|A-Z]/;
20-
2127
file.getComments().forEach(function(comment) {
2228
var stripped = comment.value.replace(/[\n\s\*]/g, '');
2329
var firstChar = stripped[0];
2430

25-
if (alphabeticalPattern.test(firstChar) && !lowerCasePattern.test(firstChar)) {
31+
if (letterPattern.test(firstChar) && !lowerCasePattern.test(firstChar)) {
2632
errors.add(
2733
'Comments must start with a lowercase letter',
2834
comment.loc.start

lib/rules/require-capitalized-comments.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
var assert = require('assert');
2+
var regenerate = require('regenerate');
3+
var Lu = require('unicode-6.3.0/categories/Lu/code-points');
4+
var Ll = require('unicode-6.3.0/categories/Ll/code-points');
5+
var Lt = require('unicode-6.3.0/categories/Lt/code-points');
6+
var Lm = require('unicode-6.3.0/categories/Lm/code-points');
7+
var Lo = require('unicode-6.3.0/categories/Lo/code-points');
28

3-
var upperCasePattern = /[A-Z]/;
4-
var alphabeticalPattern = /[a-z|A-Z]/;
9+
var letterPattern = regenerate(Lu, Ll, Lt, Lm, Lo).toRegExp();
10+
var upperCasePattern = regenerate(Lu).toRegExp();
511

612
module.exports = function() {};
713

@@ -23,7 +29,7 @@ module.exports.prototype = {
2329
file.getComments().forEach(function(comment) {
2430
var stripped = comment.value.replace(/[\n\s\*]/g, '');
2531
var firstChar = stripped[0];
26-
var isLetter = firstChar && alphabeticalPattern.test(firstChar);
32+
var isLetter = firstChar && letterPattern.test(firstChar);
2733

2834
if (!isLetter) {
2935
inTextBlock = false;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
"vow": "~0.4.3",
4040
"vow-fs": "~0.3.1",
4141
"xmlbuilder": "~2.4.0",
42-
"supports-color": "~1.2.0"
42+
"supports-color": "~1.2.0",
43+
"unicode-6.3.0": "~0.1.5",
44+
"regenerate": "~1.0.1"
4345
},
4446
"devDependencies": {
4547
"browserify": "~6.2.0",

test/rules/disallow-capitalized-comments.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ describe('rules/disallow-capitalized-comments', function() {
1717
assert(checker.checkString('/**\n * Invalid\n */').getErrorCount() === 1);
1818
assert(checker.checkString('/* Invalid */').getErrorCount() === 1);
1919
assert(checker.checkString('/*\n Invalid\n */').getErrorCount() === 1);
20+
assert(checker.checkString('//Über').getErrorCount() === 1);
21+
assert(checker.checkString('//Π').getErrorCount() === 1);
2022
});
2123

2224
it('should not report on a lowercase start of a comment', function() {
2325
assert(checker.checkString('//valid').isEmpty());
2426
assert(checker.checkString('// valid').isEmpty());
2527
assert(checker.checkString('/** valid */').isEmpty());
28+
assert(checker.checkString('//über').isEmpty());
29+
assert(checker.checkString('//π').isEmpty());
2630
});
2731

2832
it('should not report on comments that start with a non-alphabetical character', function() {

test/rules/require-capitalized-comments.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ describe('rules/require-capitalized-comments', function() {
2222
assert(checker.checkString('/**\n * invalid\n*/').getErrorCount() === 1);
2323
assert(checker.checkString('//\n// invalid\n//').getErrorCount() === 1);
2424
assert(checker.checkString('/*\ninvalid\n*/').getErrorCount() === 1);
25+
assert(checker.checkString('//über').getErrorCount() === 1);
26+
assert(checker.checkString('//π').getErrorCount() === 1);
2527
});
2628

2729
it('should not report an uppercase start of a comment', function() {
@@ -30,6 +32,8 @@ describe('rules/require-capitalized-comments', function() {
3032
assertEmpty('/** Valid */');
3133
assertEmpty('//\n// Valid\n//');
3234
assertEmpty('/*\nValid\n*/');
35+
assertEmpty('//Über');
36+
assertEmpty('//∏');
3337
});
3438

3539
it('should not report on comments that start with a non-alphabetical character', function() {
@@ -89,5 +93,10 @@ describe('rules/require-capitalized-comments', function() {
8993
'// and has one or more non-capitalized lines',
9094
'// afterwards'
9195
].join('\n'));
96+
97+
assert(checker.checkString([
98+
'// Über',
99+
'// diese Funktion'
100+
].join('\n')).isEmpty());
92101
});
93102
});

0 commit comments

Comments
 (0)