Skip to content

Commit 5ef341d

Browse files
addaleaxrichardlau
authored andcommitted
rules: skip line-length rule for URLs and quoted lines (nodejs#30)
Fixes: nodejs#24
1 parent af88c21 commit 5ef341d

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

lib/rules/line-length.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ module.exports = {
3131
var failed = false
3232
for (let i = 0; i < parsed.body.length; i++) {
3333
const line = parsed.body[i]
34+
// Skip quoted lines, e.g. for original commit messages of V8 backports.
35+
if (line.startsWith(' '))
36+
continue
37+
// Skip lines with URLs.
38+
if (/https?:\/\//.test(line))
39+
continue
3440
if (line.length > len) {
3541
failed = true
3642
context.report({

test/rules/line-length.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,69 @@ ${'aaa'.repeat(30)}`
6767
tt.end()
6868
})
6969

70+
t.test('quoted lines', (tt) => {
71+
const v = new Validator()
72+
const context = new Commit({
73+
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
74+
, author: {
75+
name: 'Evan Lucas'
76+
, email: '[email protected]'
77+
, date: '2016-04-12T19:42:23Z'
78+
}
79+
, message: `src: make foo mor foo-ey
80+
81+
Here’s the original code:
82+
83+
${'aaa'.repeat(30)}
84+
85+
That was the original code.
86+
`
87+
}, v)
88+
89+
context.report = (opts) => {
90+
tt.pass('called report')
91+
tt.equal(opts.id, 'line-length', 'id')
92+
tt.equal(opts.string, '', 'string')
93+
tt.equal(opts.level, 'pass', 'level')
94+
}
95+
96+
Rule.validate(context, {
97+
options: {
98+
length: 72
99+
}
100+
})
101+
tt.end()
102+
})
103+
104+
t.test('URLs', (tt) => {
105+
const v = new Validator()
106+
const context = new Commit({
107+
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
108+
, author: {
109+
name: 'Evan Lucas'
110+
, email: '[email protected]'
111+
, date: '2016-04-12T19:42:23Z'
112+
}
113+
, message: `src: make foo mor foo-ey
114+
115+
https://${'very-'.repeat(80)}-long-url.org/
116+
`
117+
}, v)
118+
119+
context.report = (opts) => {
120+
tt.pass('called report')
121+
tt.equal(opts.id, 'line-length', 'id')
122+
tt.equal(opts.string, '', 'string')
123+
tt.equal(opts.level, 'pass', 'level')
124+
}
125+
126+
Rule.validate(context, {
127+
options: {
128+
length: 72
129+
}
130+
})
131+
tt.end()
132+
})
133+
70134
t.end()
71135
})

test/validator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ test('Validator - real commits', (t) => {
205205
const filtered = msgs.filter((item) => {
206206
return item.level === 'fail'
207207
})
208-
tt.equal(filtered.length, 3, 'messages.length')
208+
tt.equal(filtered.length, 2, 'messages.length')
209209
const ids = filtered.map((item) => {
210210
return item.id
211211
})
212-
const exp = ['line-length', 'line-length', 'title-length']
212+
const exp = ['line-length', 'title-length']
213213
tt.deepEqual(ids.sort(), exp.sort(), 'message ids')
214214
tt.end()
215215
})

0 commit comments

Comments
 (0)