forked from pugjs/pug-lint
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This rule reports lines in Pug file that exceed the specified length. Related to pugjs#3
- Loading branch information
1 parent
d87bbb3
commit 1909828
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// # maximumLineLength: `int` | ||
// | ||
// ## e.g.: `80` | ||
// | ||
// Lines in Pug file must not exceed the specified length. | ||
|
||
var assert = require('assert'); | ||
|
||
module.exports = function () {}; | ||
|
||
module.exports.prototype = { | ||
name: 'maximumLineLength', | ||
|
||
schema: { | ||
type: ['null', 'integer'] | ||
}, | ||
|
||
configure: function (options) { | ||
assert(typeof options === 'number', this.name + ' option requires number value or should be removed'); | ||
|
||
this._maximumLineLength = options; | ||
}, | ||
|
||
lint: function (file, errors) { | ||
var max = this._maximumLineLength; | ||
|
||
file.getLines().forEach(function (line, index) { | ||
if (line.length > max) { | ||
errors.add('Line length exceeds the maximum of ' + max + ' chars', index + 1); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module.exports = createTest; | ||
|
||
var assert = require('assert'); | ||
|
||
function createTest(linter) { | ||
describe('maximumLineLength', function () { | ||
describe('int', function () { | ||
before(function () { | ||
linter.configure({maximumLineLength: 40}); | ||
}); | ||
|
||
var ok = 'html\n' + | ||
' body\n' + | ||
' div This is a 40-char-long line ----\n' + | ||
' p other line\n'; | ||
var notOk = 'html\n' + | ||
' body\n' + | ||
' div This is a 41-char-long line -----\n' + | ||
' p other line\n'; | ||
var notOk2 = 'html\n' + | ||
' body\n' + | ||
' div This is a 41-char-long line -----\n' + | ||
' p other line\n' + | ||
' div This is a 45-char-long line ---------\n' + | ||
' p other line\n'; | ||
|
||
it('should not report normal lines', function () { | ||
assert.equal(linter.checkString(ok).length, 0); | ||
}); | ||
|
||
it('should report lines too long', function () { | ||
assert.equal(linter.checkString(notOk).length, 1); | ||
}); | ||
|
||
it('should report multiple errors', function () { | ||
var result = linter.checkString(notOk2); | ||
|
||
assert.equal(result.length, 2); | ||
assert.equal(result[0].code, 'PUG:LINT_MAXIMUMLINELENGTH'); | ||
assert.equal(result[0].line, 3); | ||
assert.equal(result[0].column, undefined); | ||
assert.equal(result[1].code, 'PUG:LINT_MAXIMUMLINELENGTH'); | ||
assert.equal(result[1].line, 5); | ||
assert.equal(result[1].column, undefined); | ||
}); | ||
}); | ||
}); | ||
} |