From 74c57fc11cfee665cdf94d54e35d5087753fdfb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Sat, 26 Mar 2016 10:49:17 +0200 Subject: [PATCH] Add offenders to CSSRules --- front/src/views/rule.html | 6 ++++++ lib/metadata/policies.js | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/front/src/views/rule.html b/front/src/views/rule.html index 7301e85..d6a83e8 100644 --- a/front/src/views/rule.html +++ b/front/src/views/rule.html @@ -96,6 +96,12 @@ +
+ inline CSS + + : +
+
{{offender.color1}}
{{offender.color2}}
diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index c2f2bc0..9c7b9e2 100644 --- a/lib/metadata/policies.js +++ b/lib/metadata/policies.js @@ -424,7 +424,40 @@ var policies = { "isOkThreshold": 750, "isBadThreshold": 3000, "isAbnormalThreshold": 4500, - "hasOffenders": false + "hasOffenders": true, + "offendersTransformFn": function(offenders) { + var hasInline = false; + var inlineCount = 0; + var files = []; + + offenders.forEach(function(line) { + if (line.indexOf('[inline CSS]: ') === 0) { + hasInline = true; + inlineCount += parseInt(line.substr(14)); + } else { + var parts = /^<(.*)>: (\d+)$/.exec(line); + + if (parts) { + files.push({ + file: parts[1], + rules: parseInt(parts[2], 10) + }); + } + } + }); + + if (hasInline) { + files.push({ + file: 'inline CSS', + rules: inlineCount + }); + } + + return { + count: files.length, + list: files + }; + } }, "cssComplexSelectors": { "tool": "phantomas",