all files / eslint-plugin-angular/rules/ no-http-callback.js

100% Statements 14/14
94.12% Branches 16/17
100% Functions 3/3
100% Lines 14/14
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                      51×                   115× 108×           51×   111× 11×   100× 24×   76× 24×          
/**
 * disallow the `$http` methods `success()` and `error()`
 *
 * Disallow the $http success and error function.
 * Instead the standard promise API should be used.
 *
 * @version 0.12.0
 * @category deprecatedAngularFeature
 */
'use strict';
 
module.exports = function(context) {
    var httpMethods = [
        'delete',
        'get',
        'head',
        'jsonp',
        'patch',
        'post',
        'put'
    ];
 
    function isHttpCall(node) {
        if (node.callee.type === 'MemberExpression') {
            return httpMethods.indexOf(node.callee.property.name) !== -1 ||
                (node.callee.object.type === 'CallExpression' && isHttpCall(node.callee.object));
        }
        Eif (node.callee.type === 'Identifier') {
            return node.callee.name === '$http';
        }
    }
 
    return {
        CallExpression: function(node) {
            if (node.callee.type !== 'MemberExpression') {
                return;
            }
            if (node.callee.property.name === 'success' && isHttpCall(node)) {
                return context.report(node, '$http success is deprecated. Use then instead');
            }
            if (node.callee.property.name === 'error' && isHttpCall(node)) {
                context.report(node, '$http error is deprecated. Use then or catch instead');
            }
        }
    };
};