-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Max Line Length | ||
|
||
Rule `max-line-length` will enforce that lines do not exceed a max length / limit. | ||
|
||
## Examples | ||
|
||
When enabled, the following are disallowed: | ||
|
||
```scss | ||
.really--long--class-name--that-unfortunately--isnt--very--succint--and-looks-stupid { | ||
color: red; | ||
} | ||
|
||
// ============================================================================== | ||
// | ||
// This comment is too long clearly, we should probably make sure we have a rule to | ||
// determine when we breach this length | ||
// | ||
// ============================================================================== | ||
``` |
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,32 @@ | ||
'use strict'; | ||
|
||
var helpers = require('../helpers'); | ||
|
||
module.exports = { | ||
'name': 'max-line-length', | ||
'defaults': { | ||
length: 80 | ||
}, | ||
'detect': function (ast, parser) { | ||
var result = []; | ||
|
||
ast.traverseByType('space', function (space) { | ||
var lineLength = 0; | ||
if (helpers.hasEOL(space.content)) { | ||
lineLength = space.start.column - 1; | ||
} | ||
|
||
if (lineLength > parser.options.length) { | ||
result = helpers.addUnique(result, { | ||
'ruleId': parser.rule.name, | ||
'severity': parser.severity, | ||
'line': space.start.line, | ||
'column': 0, | ||
'message': 'line ' + space.start.line + ' exceeds the maximum line length of ' + parser.options.length | ||
}); | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
}; |
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,63 @@ | ||
'use strict'; | ||
|
||
var lint = require('./_lint'); | ||
|
||
////////////////////////////// | ||
// SCSS syntax tests | ||
////////////////////////////// | ||
describe('max-line-length - scss', function () { | ||
var file = lint.file('max-line-length.scss'); | ||
|
||
it('enforce [default]', function (done) { | ||
lint.test(file, { | ||
'max-line-length': 1 | ||
}, function (data) { | ||
lint.assert.equal(5, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('enforce [length: 79]', function (done) { | ||
lint.test(file, { | ||
'max-line-length': [ | ||
1, | ||
{ | ||
length: 79 | ||
} | ||
] | ||
}, function (data) { | ||
lint.assert.equal(8, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
////////////////////////////// | ||
// Sass syntax tests | ||
////////////////////////////// | ||
describe('max-line-length - sass', function () { | ||
var file = lint.file('max-line-length.sass'); | ||
|
||
it('enforce', function (done) { | ||
lint.test(file, { | ||
'max-line-length': 1 | ||
}, function (data) { | ||
lint.assert.equal(5, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('enforce [length: 79]', function (done) { | ||
lint.test(file, { | ||
'max-line-length': [ | ||
1, | ||
{ | ||
length: 79 | ||
} | ||
] | ||
}, function (data) { | ||
lint.assert.equal(8, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
.really--long--class-name--that-unfortunately--isnt--very--succint--and-looks-stupid | ||
color: red | ||
|
||
@function($aReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongVariableName) | ||
@return 'test' | ||
|
||
// ============================================================================== | ||
// | ||
// This comment is too long clearly, we should probably make sure we have a rule to | ||
// determine when we breach this length | ||
// | ||
// ============================================================================== | ||
// ============================================================================= | ||
// | ||
// This comment comment on the other hand should be the perfect length, unless a | ||
// user decides to make their max line length === 79! | ||
// | ||
// ============================================================================= |
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,22 @@ | ||
.really--long--class-name--that-unfortunately--isnt--very--succint--and-looks-stupid { | ||
color: red; | ||
} | ||
|
||
@function($aReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongVariableName) { | ||
@return 'test'; | ||
} | ||
|
||
// ============================================================================== | ||
// | ||
// This comment is too long clearly, we should probably make sure we have a rule to | ||
// determine when we breach this length | ||
// | ||
// ============================================================================== | ||
|
||
|
||
// ============================================================================= | ||
// | ||
// This comment comment on the other hand should be the perfect length, unless a | ||
// user decides to make their max line length === 79! | ||
// | ||
// ============================================================================= |