Skip to content

Commit

Permalink
Merge pull request #842 from DanPurdy/feature/max-file-line-count
Browse files Browse the repository at this point in the history
Add max-file-line-count rule
  • Loading branch information
bgriffith authored Oct 27, 2016
2 parents d2c4ce4 + bb321ce commit 21a20eb
Show file tree
Hide file tree
Showing 6 changed files with 718 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/rules/max-file-line-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Max File Line Count

Rule `max-file-line-count` will enforce that a file's length doesn't exceed a certain number of lines

## Options

* `length`: `number`, (defaults to 300)

## Examples

When enabled, the following are disallowed:

```scss
/*
* line count is represented along the
* left hand side of the following example
*/
1| .test {
2| color: red
3| }
=====
~ snip ~
=====
299| .bar {
300| color: blue;
301| }
```
1 change: 1 addition & 0 deletions lib/config/sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ rules:
indentation: 1
leading-zero: 1
max-line-length: 0
max-file-line-count: 0
nesting-depth: 1
property-sort-order: 1
pseudo-element: 1
Expand Down
25 changes: 25 additions & 0 deletions lib/rules/max-file-line-count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var helpers = require('../helpers');

module.exports = {
'name': 'max-file-line-count',
'defaults': {
length: 300
},
'detect': function (ast, parser) {
var result = [];

if (ast.end.line > parser.options.length) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': ast.end.line,
'column': 0,
'message': 'This file has ' + ast.end.line + ' lines, which exceeds the maximum of ' + parser.options.length + ' lines allowed.',
'severity': parser.severity
});
}

return result;
}
};
63 changes: 63 additions & 0 deletions tests/rules/max-file-line-count.js
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-file-line-count - scss', function () {
var file = lint.file('max-file-line-count.scss');

it('enforce [default]', function (done) {
lint.test(file, {
'max-file-line-count': 1
}, function (data) {
lint.assert.equal(1, data.warningCount);
done();
});
});

it('enforce [length: 3000]', function (done) {
lint.test(file, {
'max-file-line-count': [
1,
{
length: 3000
}
]
}, function (data) {
lint.assert.equal(0, data.warningCount);
done();
});
});
});

//////////////////////////////
// Sass syntax tests
//////////////////////////////
describe('max-file-line-count - sass', function () {
var file = lint.file('max-file-line-count.sass');

it('enforce', function (done) {
lint.test(file, {
'max-file-line-count': 1
}, function (data) {
lint.assert.equal(1, data.warningCount);
done();
});
});

it('enforce [length: 3000]', function (done) {
lint.test(file, {
'max-file-line-count': [
1,
{
length: 3000
}
]
}, function (data) {
lint.assert.equal(0, data.warningCount);
done();
});
});
});
Loading

0 comments on commit 21a20eb

Please sign in to comment.