-
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.
Merge pull request #842 from DanPurdy/feature/max-file-line-count
Add max-file-line-count rule
- Loading branch information
Showing
6 changed files
with
718 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,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| } | ||
``` |
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,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; | ||
} | ||
}; |
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-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(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.