/
collection-model.js
45 lines (39 loc) · 1.61 KB
/
collection-model.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
/**
* @fileoverview Require all collections to declare model
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
var helper = require("../../backbone-helper.js");
module.exports = function(context) {
var settings = context.settings || /* istanbul ignore next */ {};
var backboneCollection = [];
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
return {
"CallExpression": function(node) {
if (helper.isBackboneCollection(node, settings.backbone)) {
backboneCollection.push({ node: node, found: false });
}
},
"CallExpression:exit": function(node) {
var lastCollection = backboneCollection[backboneCollection.length - 1];
if (backboneCollection.length > 0 && lastCollection.node === node) {
if (!lastCollection.found) {
context.report(node, "All collections should have model declared");
}
backboneCollection.pop();
}
},
"Identifier": function(node) {
if (backboneCollection.length > 0 && node.name === "model") {
if (helper.checkIfPropertyInBackboneCollection(node, settings.backbone)) {
backboneCollection[backboneCollection.length - 1].found = true;
}
}
}
};
};