-
Notifications
You must be signed in to change notification settings - Fork 529
/
extends-before-declarations.js
48 lines (40 loc) · 1.27 KB
/
extends-before-declarations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var helpers = require('../helpers');
module.exports = {
'name': 'extends-before-declarations',
'defaults': {},
'detect': function (ast, parser) {
var result = [],
error;
ast.traverseByType('block', function (block) {
var lastDeclaration = null;
block.forEach(function (item, j) {
if (item.is('include') || item.is('extend')) {
if (item.contains('atkeyword')) {
var atkeyword = item.first('atkeyword');
if (atkeyword.contains('ident')) {
var ident = atkeyword.first('ident');
if (ident.content === 'extend') {
if (j > lastDeclaration && lastDeclaration !== null) {
error = {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': 'Extends should come before declarations',
'severity': parser.severity
};
result = helpers.addUnique(result, error);
}
}
}
}
}
if (item.is('declaration')) {
lastDeclaration = j;
}
});
lastDeclaration = null;
});
return result;
}
};