'use strict';

var COMPLEX_SELECTOR_THRESHOLD = 3;

function rule(analyzer) {
	analyzer.setMetric('complexSelectors');

	analyzer.on('selector', function(rule, selector, expressions) {
		if (expressions.length > COMPLEX_SELECTOR_THRESHOLD) {
			analyzer.incrMetric('complexSelectors');
			analyzer.addOffender('complexSelectors', selector);
		}
	});
}

rule.description = 'Reports too complex CSS selectors';
module.exports = rule;

@@ -112,16 +112,90 @@
 tors');%0A
+%09analyzer.setMetric('complexSelectorsByAttribute');%0A%0A%09// #foo .bar ul li a
 %0A%09analyz
@@ -416,16 +416,647 @@
 %09%09%7D%0A%09%7D);
+%0A%0A%09// .foo%5Btype*=bar%5D%0A%09// @see http://www.w3.org/TR/css3-selectors/#attribute-selectors%0A%09analyzer.on('expression', function(selector, expression) %7B%0A%09%09if (typeof expression.attributes !== 'undefined') %7B%0A%09%09%09switch (expression.attributes%5B0%5D.operator) %7B%0A%09%09%09%09case '=':%0A%09%09%09%09%09break;%0A%0A%09%09%09%09case '~=': // contains value in a whitespace-separated list of words%0A%09%09%09%09case '%7C=': // starts with value or value-%0A%09%09%09%09case '%5E=': // starts with%0A%09%09%09%09case '$=': // ends with%0A%09%09%09%09case '*=': // contains%0A%09%09%09%09%09analyzer.incrMetric('complexSelectorsByAttribute');%0A%09%09%09%09%09analyzer.addOffender('complexSelectorsByAttribute', selector);%0A%09%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D);
 %0A%7D%0A%0Arule

add a metric