Skip to content

Commit

Permalink
🎨 Simplify rule functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy authored Oct 26, 2016
1 parent 097adcf commit 04764e4
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions lib/rules/max-file-line-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,20 @@

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

/**
* Get the 'last' node of the tree
*
* @param {Object} node - The node whose last child we want to return
* @returns {Object} The last node
*/
var getLastNode = function (node) {
var last = node.last();

return last ? getLastNode(last) : node;
};

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

// If the syntax is Sass we must recursively loop to determine the last node.
// This is not required for SCSS which will always use the last node in the
// content of the parent stylesheet node
if (ast.syntax === 'sass') {
last = getLastNode(ast);
}
else {
last = ast.content[ast.content.length - 1];
}

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

0 comments on commit 04764e4

Please sign in to comment.