Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/rules/line-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ module.exports = {
var failed = false
for (let i = 0; i < parsed.body.length; i++) {
const line = parsed.body[i]
// Skip quoted lines, e.g. for original commit messages of V8 backports.
if (line.startsWith(' '))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this have four space characters? The test actually tests with four space characters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure … switched to 4 spaces for now, yes

continue
// Skip lines with URLs.
if (line.match(/https?:\/\//))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think RegExp#test would be better here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye There’s 0 difference here, right? Anyway, done!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, there will be no difference. I was going for idiomatic code 🙂

continue
if (line.length > len) {
failed = true
context.report({
Expand Down
64 changes: 64 additions & 0 deletions test/rules/line-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,69 @@ ${'aaa'.repeat(30)}`
tt.end()
})

t.test('quoted lines', (tt) => {
const v = new Validator()
const context = new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
, author: {
name: 'Evan Lucas'
, email: '[email protected]'
, date: '2016-04-12T19:42:23Z'
}
, message: `src: make foo mor foo-ey

Here’s the original code:

${'aaa'.repeat(30)}

That was the original code.
`
}, v)

context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'line-length', 'id')
tt.equal(opts.string, '', 'string')
tt.equal(opts.level, 'pass', 'level')
}

Rule.validate(context, {
options: {
length: 72
}
})
tt.end()
})

t.test('URLs', (tt) => {
const v = new Validator()
const context = new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
, author: {
name: 'Evan Lucas'
, email: '[email protected]'
, date: '2016-04-12T19:42:23Z'
}
, message: `src: make foo mor foo-ey

https://${'very-'.repeat(80)}-long-url.org/
`
}, v)

context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'line-length', 'id')
tt.equal(opts.string, '', 'string')
tt.equal(opts.level, 'pass', 'level')
}

Rule.validate(context, {
options: {
length: 72
}
})
tt.end()
})

t.end()
})
4 changes: 2 additions & 2 deletions test/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ test('Validator - real commits', (t) => {
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 3, 'messages.length')
tt.equal(filtered.length, 2, 'messages.length')
const ids = filtered.map((item) => {
return item.id
})
const exp = ['line-length', 'line-length', 'title-length']
const exp = ['line-length', 'title-length']
tt.deepEqual(ids.sort(), exp.sort(), 'message ids')
tt.end()
})
Expand Down