1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var utils = require('./utils/utils');
|
13 |
|
14 | module.exports = {
|
15 | meta: {
|
16 | docs: {
|
17 | url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/typecheck-string.md'
|
18 | },
|
19 | schema: []
|
20 | },
|
21 | create: function(context) {
|
22 | function recordError(node, origin) {
|
23 | if (node.type === 'Literal' && (node.value === 'string' || node.value === '[object String]')) {
|
24 | context.report(origin, 'You should use the angular.isString method', {});
|
25 | }
|
26 | }
|
27 |
|
28 | return {
|
29 |
|
30 | BinaryExpression: function(node) {
|
31 | if (node.operator === '===' || node.operator === '!==') {
|
32 | if (utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)) {
|
33 | recordError(node.right, node);
|
34 | } else if (utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)) {
|
35 | recordError(node.left, node);
|
36 | }
|
37 | }
|
38 | }
|
39 | };
|
40 | }
|
41 | };
|