Skip to content

Commit e94b9eb

Browse files
Trottjoyeecheung
authored andcommitted
lib: add test for lowercase first word in title
1 parent 740df83 commit e94b9eb

File tree

2 files changed

+72
-8
lines changed

2 files changed

+72
-8
lines changed

lib/rules/title-format.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
, recommended: true
1010
}
1111
, validate: (context, rule) => {
12+
let pass = true
1213
if (/[\.\?\!]$/.test(context.title)) {
1314
context.report({
1415
id: id
@@ -18,14 +19,29 @@ module.exports = {
1819
, column: context.title.length
1920
, level: 'fail'
2021
})
21-
return
22+
pass = false
2223
}
2324

24-
context.report({
25-
id: id
26-
, message: 'Title is formatted correctly.'
27-
, string: ''
28-
, level: 'pass'
29-
})
25+
const result = /^(.+?): [A-Z]/.exec(context.title)
26+
if (result) {
27+
context.report({
28+
id: id
29+
, message: 'First word after subsystem(s) in title should be lowercase.'
30+
, string: context.title
31+
, line: 0
32+
, column: result[1].length + 3
33+
, level: 'fail'
34+
})
35+
pass = false
36+
}
37+
38+
if (pass) {
39+
context.report({
40+
id: id
41+
, message: 'Title is formatted correctly.'
42+
, string: ''
43+
, level: 'pass'
44+
})
45+
}
3046
}
3147
}

test/validator.js

+49-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ Date: Thu Mar 3 10:10:46 2016 -0600
113113
test: check memoryUsage properties.
114114
`
115115

116+
const str8 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
117+
Author: Wyatt Preul <[email protected]>
118+
Date: Thu Mar 3 10:10:46 2016 -0600
119+
120+
test: Check memoryUsage properties
121+
`
122+
123+
const str9 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
124+
Author: Wyatt Preul <[email protected]>
125+
Date: Thu Mar 3 10:10:46 2016 -0600
126+
127+
test: Check memoryUsage properties.
128+
`
129+
116130
test('Validator - misc', (t) => {
117131
const v = new Validator()
118132

@@ -278,7 +292,7 @@ test('Validator - real commits', (t) => {
278292
})
279293
})
280294

281-
t.test('trailing punctuation in first line', (tt) => {
295+
t.test('trailing punctuation in title line', (tt) => {
282296
const v = new Validator({
283297
'validate-metadata': false
284298
})
@@ -296,5 +310,39 @@ test('Validator - real commits', (t) => {
296310
})
297311
})
298312

313+
t.test('first word is lowercase in title line', (tt) => {
314+
const v = new Validator({
315+
'validate-metadata': false
316+
})
317+
v.lint(str8)
318+
v.on('commit', (data) => {
319+
const msgs = data.messages
320+
const filtered = msgs.filter((item) => {
321+
return item.level === 'fail'
322+
})
323+
tt.equal(filtered.length, 1, 'messages.length')
324+
tt.equal(filtered[0].message,
325+
'First word after subsystem(s) in title should be lowercase.',
326+
'message')
327+
tt.equal(filtered[0].column, 7, 'column')
328+
tt.end()
329+
})
330+
})
331+
332+
t.test('more than one formatting error in title line', (tt) => {
333+
const v = new Validator({
334+
'validate-metadata': false
335+
})
336+
v.lint(str9)
337+
v.on('commit', (data) => {
338+
const msgs = data.messages
339+
const filtered = msgs.filter((item) => {
340+
return item.level === 'fail'
341+
})
342+
tt.equal(filtered.length, 2, 'messages.length')
343+
tt.end()
344+
})
345+
})
346+
299347
t.end()
300348
})

0 commit comments

Comments
 (0)