|
@@ -1,4 +1,6 @@
|
|
|
-{
|
|
|
+var debug = require('debug')('ylt:policies');
|
|
|
+
|
|
|
+var policies = {
|
|
|
"DOMelementsCount": {
|
|
|
"tool": "phantomas",
|
|
|
"label": "DOM elements count",
|
|
@@ -103,24 +105,61 @@
|
|
|
"isBadThreshold": 50,
|
|
|
"isAbnormalThreshold": 200
|
|
|
},
|
|
|
- "inBodyDomManipulations": {
|
|
|
- "tool": "ylt",
|
|
|
- "label": "DOM manipulations in body",
|
|
|
- "message": "<p>This metric counts the number of DOM queries, DOM inserts, binds, etc. made by the JavaScript before the DOMContentLoaded event.</p><p>Wait for this event before manipulating the DOM. Do not execute JavaScript in the middle of the BODY as it slows down the construction of the DOM and makes a poor maintainability. This is what i call spaghetti code.</p><p>The JS Timeline tab can help you identify what's happening.</p>",
|
|
|
- "isOkThreshold": 10,
|
|
|
- "isBadThreshold": 50,
|
|
|
- "isAbnormalThreshold": 100
|
|
|
- },
|
|
|
"jQueryVersion": {
|
|
|
- "tool": "ylt",
|
|
|
"label": "jQuery version",
|
|
|
"message": "<p>Current latest versions of jQuery are 1.11 (with support for old IE versions) and 2.1 (without).</p><p>Each new version of jQuery optimizes performances. Do not keep an old version of jQuery. Updating can sometimes break a few things, but it is generally quite easy to fix them up. So don't hesitate.</p>",
|
|
|
- "isOkThreshold": 1,
|
|
|
- "isBadThreshold": 2,
|
|
|
- "isAbnormalThreshold": 3
|
|
|
+ "scoreFn": function(data) {
|
|
|
+ var differentVersions = data.toolsResults.phantomas.metrics.jQueryDifferentVersions;
|
|
|
+
|
|
|
+ if (differentVersions === 0 || differentVersions > 1) {
|
|
|
+ // Not applicable
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ var value = data.toolsResults.phantomas.metrics.jQueryVersion;
|
|
|
+ var score;
|
|
|
+
|
|
|
+ if (value.indexOf('1.11.') === 0 ||
|
|
|
+ value.indexOf('1.12.') === 0 ||
|
|
|
+ value.indexOf('2.1.') === 0 ||
|
|
|
+ value.indexOf('2.2.') === 0 ||
|
|
|
+ value.indexOf('3.0.') === 0) {
|
|
|
+ score = 100;
|
|
|
+ } else if (value.indexOf('1.10.') === 0 ||
|
|
|
+ value.indexOf('2.0.') === 0) {
|
|
|
+ score = 90;
|
|
|
+ } else if (value.indexOf('1.9.') === 0) {
|
|
|
+ score = 70;
|
|
|
+ } else if (value.indexOf('1.8.') === 0) {
|
|
|
+ score = 50;
|
|
|
+ } else if (value.indexOf('1.7.') === 0) {
|
|
|
+ score = 40;
|
|
|
+ } else if (value.indexOf('1.6.') === 0) {
|
|
|
+ score = 30;
|
|
|
+ } else if (value.indexOf('1.5.') === 0) {
|
|
|
+ score = 20;
|
|
|
+ } else if (value.indexOf('1.4.') === 0) {
|
|
|
+ score = 10;
|
|
|
+ } else if (value.indexOf('1.3.') === 0) {
|
|
|
+ score = 0;
|
|
|
+ } else if (value.indexOf('1.2.') === 0) {
|
|
|
+ score = 0;
|
|
|
+ } else {
|
|
|
+ debug('Unknown jQuery version "%s"', value);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ value: value,
|
|
|
+ score: score,
|
|
|
+ bad: value < 100,
|
|
|
+ abnormal: false,
|
|
|
+ abnormalityScore: 0
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
"jQueryDifferentVersions": {
|
|
|
- "tool": "ylt",
|
|
|
+ "tool": "phantomas",
|
|
|
"label": "Several versions loaded",
|
|
|
"message": "<p>jQuery is a heavy library. You should <b>never<b> load jQuery more than one on the same page.</p>",
|
|
|
"isOkThreshold": 1,
|
|
@@ -367,4 +406,6 @@
|
|
|
"isBadThreshold": 25,
|
|
|
"isAbnormalThreshold": 50
|
|
|
}
|
|
|
-}
|
|
|
+};
|
|
|
+
|
|
|
+module.exports = policies;
|