all files / eslint-plugin-angular/rules/ no-jquery-angularelement.js

100% Statements 6/6
100% Branches 12/12
100% Functions 2/2
100% Lines 6/6
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                  11×                            
/**
 * disallow to wrap `angular.element` objects with `jQuery` or `$`
 *
 * You should not wrap angular.element object into jQuery(), because angular.element already return jQLite element
 * @version 0.1.0
 * @category angularWrapper
 */
'use strict';
 
module.exports = function(context) {
    return {
 
        MemberExpression: function(node) {
            if (node.object.name === 'angular' && node.property.name === 'element') {
                if (node.parent !== undefined && node.parent.parent !== undefined &&
                        node.parent.parent.type === 'CallExpression' &&
                        node.parent.parent.callee.type === 'Identifier' &&
                        (node.parent.parent.callee.name === 'jQuery' || node.parent.parent.callee.name === '$')) {
                    context.report(node, 'angular.element returns already a jQLite element. No need to wrap with the jQuery object', {});
                }
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];