Copy offenders from jsCount etc. to the requests rule

This commit is contained in:
Gaël Métais
2015-01-05 15:51:02 +01:00
parent aabbf882df
commit d78716c873
5 changed files with 24 additions and 5 deletions
+2 -1
View File
@@ -301,7 +301,8 @@ var policies = {
"message": "<p>This is one of the most important performance rule. Every request is slowing down the page loading.</p><p>There are several technics to reduce their number:<ul><li>Concatenate JS files</li><li>Concatenate CSS files</li><li>Embed or inline small JS or CSS files in the HTML</li><li>Create sprites or icon fonts</li><li>Base64 encode small images in HTML or stylesheets</li><li>Use lazyloading for images</li></ul></p>",
"isOkThreshold": 15,
"isBadThreshold": 100,
"isAbnormalThreshold": 200
"isAbnormalThreshold": 200,
"takeOffendersFrom": ["htmlCount", "jsCount", "cssCount", "imageCount", "webfontCount", "videoCount", "jsonCount", "jsonCount"]
},
"htmlCount": {
"tool": "phantomas",
+15 -2
View File
@@ -4,6 +4,7 @@ var RulesChecker = function() {
'use strict';
this.check = function(data, policies) {
/*jshint loopfunc:true */
var results = {};
@@ -23,9 +24,21 @@ var RulesChecker = function() {
policy: policy
};
// Take DOMqueriesAvoidable's offenders from DOMqueriesDuplicated.
// Take DOMqueriesAvoidable's offenders from DOMqueriesDuplicated, for example.
if (policy.takeOffendersFrom) {
data.toolsResults[policy.tool].offenders[metricName] = data.toolsResults[policy.tool].offenders[policy.takeOffendersFrom];
var fromList = policy.takeOffendersFrom;
var offenders = [];
// takeOffendersFrom option can be a string or an array of strings.
if (typeof fromList === 'string') {
fromList = [fromList];
}
fromList.forEach(function(from) {
offenders = offenders.concat(data.toolsResults[policy.tool].offenders[from]);
});
data.toolsResults[policy.tool].offenders[metricName] = offenders;
}
if (data.toolsResults[policy.tool].offenders &&
+1
View File
@@ -14,6 +14,7 @@
"metric1": [],
"metric2": [],
"metric3": ["offender1", "offender2"],
"metric4": ["offender3"],
"metric5": []
}
},
+4 -1
View File
@@ -57,6 +57,7 @@
"isAbnormalThreshold": 5000
},
"value": 1000,
"offenders": ["offender3"],
"bad": false,
"abnormal": false,
"score": 100,
@@ -69,9 +70,11 @@
"message": "A great message",
"isOkThreshold": 1000,
"isBadThreshold": 3000,
"isAbnormalThreshold": 5000
"isAbnormalThreshold": 5000,
"takeOffendersFrom": ["metric3", "metric4"]
},
"value": 3000,
"offenders": ["offender1", "offender2", "offender3"],
"bad": true,
"abnormal": false,
"score": 0,
+2 -1
View File
@@ -38,7 +38,8 @@
"message": "A great message",
"isOkThreshold": 1000,
"isBadThreshold": 3000,
"isAbnormalThreshold": 5000
"isAbnormalThreshold": 5000,
"takeOffendersFrom": ["metric3", "metric4"]
},
"metric6": {
"tool": "tool1",