forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixes-url.js
70 lines (66 loc) · 1.47 KB
/
fixes-url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict'
const id = 'fixes-url'
module.exports = {
id: id
, meta: {
description: 'enforce format of Fixes URLs'
, recommended: true
}
, defaults: {}
, options: {}
, validate: (context, rule) => {
const parsed = context.toJSON()
if (!Array.isArray(parsed.fixes) || !parsed.fixes.length) {
context.report({
id: id
, message: 'skipping fixes-url'
, string: ''
, level: 'skip'
})
return
}
for (const url of parsed.fixes) {
if (url[0] === '#') {
// See nodejs/node#2aa376914b621018c5784104b82c13e78ee51307
// for an example
const { line, column } = findLineAndColumn(context.body, url)
context.report({
id: id
, message: 'Fixes must be a url, not an issue number.'
, string: url
, line: line
, column: column
, level: 'fail'
})
} else {
const { line, column } = findLineAndColumn(context.body, url)
context.report({
id: id
, message: 'Valid fixes url'
, string: url
, line: line
, column: column
, level: 'pass'
})
}
}
}
}
function findLineAndColumn(body, str) {
for (var i = 0; i < body.length; i++) {
const l = body[i]
if (~l.indexOf('Fixes')) {
const idx = l.indexOf(str)
if (idx !== -1) {
return {
line: i
, column: idx
}
}
}
}
return {
line: -1
, column: -1
}
}