浏览代码

Add offenders to CSSRules

Gaël Métais 9 年之前
父节点
当前提交
74c57fc11c
共有 2 个文件被更改,包括 40 次插入1 次删除
  1. 6 0
      front/src/views/rule.html
  2. 34 1
      lib/metadata/policies.js

+ 6 - 0
front/src/views/rule.html

@@ -96,6 +96,12 @@
                         </span>
                         </span>
                     </div>
                     </div>
 
 
+                    <div ng-if="policyName === 'cssRules'">
+                        <span ng-if="offender.file === 'inline CSS'">inline CSS</span>
+                        <span ng-if="offender.file !== 'inline CSS'"><url-link url="offender.file" max-length="80"></url-link></span>
+                        : <ng-pluralize count="offender.rules" when="{'0': '0 rule', 'one':'1 rule','other':'{} rules'}"></ng-pluralize>
+                    </div>
+
                     <div ng-if="policyName === 'similarColors'">
                     <div ng-if="policyName === 'similarColors'">
                         <div class="similarColors checker"><div ng-style="{'background-color': offender.color1, 'color': offender.isDark ? '#FFF' : '#000'}">{{offender.color1}}</div><div ng-style="{'background-color': offender.color2, 'color': offender.isDark ? '#FFF' : '#000'}">{{offender.color2}}</div></div>
                         <div class="similarColors checker"><div ng-style="{'background-color': offender.color1, 'color': offender.isDark ? '#FFF' : '#000'}">{{offender.color1}}</div><div ng-style="{'background-color': offender.color2, 'color': offender.isDark ? '#FFF' : '#000'}">{{offender.color2}}</div></div>
                     </div>
                     </div>

+ 34 - 1
lib/metadata/policies.js

@@ -424,7 +424,40 @@ var policies = {
         "isOkThreshold": 750,
         "isOkThreshold": 750,
         "isBadThreshold": 3000,
         "isBadThreshold": 3000,
         "isAbnormalThreshold": 4500,
         "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": {
     "cssComplexSelectors": {
         "tool": "phantomas",
         "tool": "phantomas",