Skip to content

Commit

Permalink
🐛 Update mixin-before-declarations fixes sasstools#80
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy committed Sep 3, 2015
1 parent 2ba40b4 commit bdf4669
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions lib/rules/mixins-before-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@ module.exports = {
]
},
'detect': function (ast, parser) {
var result = [],
error;
var result = [];
var error;

ast.traverseByType('block', function (block) {
var lastDeclaration = null;
block.traverse(function (item, j) {
if (item.type === 'include') {
if (j > lastDeclaration && lastDeclaration !== null) {
item.forEach('simpleSelector', function (name) {
if (parser.options.exclude.indexOf(name.content[0].content) === -1) {
error = {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': 'Mixins should come before declarations',
'severity': parser.severity
};
result = helpers.addUnique(result, error);
}
});
}
ast.traverseByType('include', function (node, i, parent) {
var depth = 0;
var declarationCount = [depth];

parent.traverse( function (item) {
if (item.type === 'ruleset') {
depth++;
declarationCount[depth] = 0;
}
if (item.type === 'declaration') {
lastDeclaration = j;
declarationCount[depth]++;
}
else if (item.type === 'include') {
item.forEach('simpleSelector', function (name) {
if (parser.options.exclude.indexOf(name.content[0].content) === -1 && declarationCount[depth] > 0) {
error = {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': 'Mixins should come before declarations',
'severity': parser.severity
};
result = helpers.addUnique(result, error);
}
});
}
});
lastDeclaration = null;
});

return result;
}
};

0 comments on commit bdf4669

Please sign in to comment.