UNPKG

1.36 kBJavaScriptView Raw
1/**
2 * use `angular.isNumber` instead of `typeof` comparisons
3 *
4 * You should use the angular.isNumber method instead of the default JavaScript implementation (typeof 3 === "[object Number]").
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 docs: {
17 url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/typecheck-number.md'
18 },
19 schema: []
20 },
21 create: function(context) {
22 function recordError(node, origin) {
23 if (node.type === 'Literal' && (node.value === 'number' || node.value === '[object Number]')) {
24 context.report(origin, 'You should use the angular.isNumber method', {});
25 }
26 }
27
28
29 return {
30
31 BinaryExpression: function(node) {
32 if (node.operator === '===' || node.operator === '!==') {
33 if (utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)) {
34 recordError(node.right, node);
35 } else if (utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)) {
36 recordError(node.left, node);
37 }
38 }
39 }
40 };
41 }
42};