UNPKG

1.22 kBJavaScriptView Raw
1/**
2 * use `angular.isObject` instead of `typeof` comparisons
3 *
4 * You should use the angular.isObject method instead of the default JavaScript implementation (typeof {} === "[object Object]").
5 *
6 * @version 0.1.0
7 * @category angularWrapper
8 * @sinceAngularVersion 1.x
9 */
10'use strict';
11
12var utils = require('./utils/utils');
13
14module.exports = {
15 meta: {
16 schema: []
17 },
18 create: function(context) {
19 function recordError(node, origin) {
20 if (node.type === 'Literal' && (node.value === 'object' || node.value === '[object Object]')) {
21 context.report(origin, 'You should use the angular.isObject method', {});
22 }
23 }
24
25 return {
26 BinaryExpression: function(node) {
27 if (node.operator === '===' || node.operator === '!==') {
28 if (utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)) {
29 recordError(node.right, node);
30 } else if (utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)) {
31 recordError(node.left, node);
32 }
33 }
34 }
35 };
36 }
37};