Break out wrap test to own function

This commit is contained in:
Kevin Sawicki
2013-06-06 08:32:47 -07:00
parent eaf5b8bc8e
commit 2f8c45aec4
2 changed files with 11 additions and 6 deletions

View File

@@ -106,6 +106,8 @@ module.exports = (grunt) ->
coffeelint:
options:
indentation:
level: 'warn'
no_empty_param_list:
level: 'error'
max_line_length:

View File

@@ -14,18 +14,21 @@ module.exports =
currentLine = []
currentLineLength = 0
for segment in @segmentText(text.replace(/\n/g, ' '))
if /\w/.test(segment) and
(currentLineLength + segment.length > wrapColumn) and
(currentLineLength > 0 or segment.length < wrapColumn)
lines.push(currentLine.join(''))
currentLine = []
currentLineLength = 0
if @wrapSegment(segment, currentLineLength, wrapColumn)
lines.push(currentLine.join(''))
currentLine = []
currentLineLength = 0
currentLine.push(segment)
currentLineLength += segment.length
lines.push(currentLine.join(''))
lines.join('\n').replace(/\s+\n/g, '\n')
wrapSegment: (segment, currentLineLength, wrapColumn) ->
/\w/.test(segment) and
(currentLineLength + segment.length > wrapColumn) and
(currentLineLength > 0 or segment.length < wrapColumn)
segmentText: (text) ->
segments = []
re = /[\s]+|[^\s]+/g