Procházet zdrojové kódy

Various adaptations for Phantomas v2

Gaël Métais před 4 roky
rodič
revize
6e6285c5ae

+ 4 - 4
front/src/views/rule.html

@@ -45,7 +45,7 @@
                     </div>
 
                     <div ng-if="policyName === 'DOMidDuplicated'">
-                        <b>{{offender.id}}</b>: {{offender.occurrences}} occurrences
+                        <b>{{offender.id}}</b>: {{offender.count}} occurrences
                     </div>
 
                     <div ng-if="policyName === 'DOMqueriesAvoidable'">
@@ -123,7 +123,7 @@
                     </div>
 
                     <div ng-if="policyName === 'cssOldPropertyPrefixes'">
-                        <b>{{offender.property}} {{offender.message}}</b>
+                        <b>{{offender.property}}</b> {{offender.message}}
                         <div ng-if="offender.rules.length" ng-click="offender.showMore = !offender.showMore" class="offenderButton">
                             <span ng-if="!offender.showMore">show</span>
                             <span ng-if="offender.showMore">hide</span>
@@ -183,8 +183,8 @@
             <h3>
                 <ng-pluralize count="fileDetails.count" when="{'one': '1 offender', 'other': '{} offenders'}"></ng-pluralize>
                 in
-                <url-link ng-if="fileDetails.url !== 'Inline CSS'" url="fileDetails.url" max-length="80"></url-link>
-                <span ng-if="fileDetails.url === 'Inline CSS'">inline CSS</span>
+                <url-link ng-if="fileDetails.url !== 'Inline CSS' && fileDetails.url !== '[inline CSS]'" url="fileDetails.url" max-length="80"></url-link>
+                <span ng-if="fileDetails.url === 'Inline CSS' || fileDetails.url === '[inline CSS]'">inline CSS</span>
             </h3>
 
             <div class="offendersTable">

+ 9 - 44
lib/metadata/policies.js

@@ -44,27 +44,7 @@ var policies = {
         "isOkThreshold": 0,
         "isBadThreshold": 5,
         "isAbnormalThreshold": 50,
-        "hasOffenders": true,
-        "offendersTransformFn": function(offenders) {
-            return {
-                count: offenders.length,
-                list: offenders.map(function(offender) {
-                    var parts = /^(.*): ?(\d+) ?occurrences$/.exec(offender);
-
-                    if (!parts) {
-                        debug('DOMidDuplicated offenders transform function error with "%s"', offender);
-                        return {
-                            parseError: offender
-                        };
-                    }
-
-                    return {
-                        id: parts[1],
-                        occurrences: parseInt(parts[2], 10)
-                    };
-                })
-            };
-        }
+        "hasOffenders": true
     },
     "DOMqueriesAvoidable": {
         "tool": "phantomas",
@@ -330,7 +310,7 @@ var policies = {
             return {
                 count: offenders.length,
                 list: offenders.map(function(offender) {
-                    if (offender === '[inline CSS] (Empty CSS was provided)') {
+                    if (offender === '[inline CSS]') {
                         return {
                             error: 'Empty style tag',
                             file: null,
@@ -339,30 +319,15 @@ var policies = {
                         };
                     }
 
-                    var parts = /^(?:(?:<([^ \(]*)>|\[inline CSS\]) ?)?(?:\((((?! @ ).)*)(?: @ (\d+):(\d+))?\))?$/.exec(offender);
-
-                    if (parts) {
-                        return {
-                            error: parts[2] || 'Unknown parsing error' + (parts[1] ? '. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.' : ''),
-                            file: parts[1] || null,
-                            line: (parts[4] && parts[5]) ? parseInt(parts[4], 10) : null,
-                            column: (parts[4] && parts[5]) ? parseInt(parts[5], 10) : null
-                        };
-                    }
-
-                    // Try another syntax
-                    parts = /^(.*) <(.*)> @ (\d+):(\d+)$/.exec(offender);
-
-                    if (parts) {
+                    if (offender.value) {
                         return {
-                            error: parts[1] || 'Unknown parsing error',
-                            file: parts[2] || null,
-                            line: parseInt(parts[3], 10),
-                            column: parseInt(parts[4], 10)
+                            error: offender.value.message || 'Unknown parsing error' + (parts[1] ? '. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.' : ''),
+                            file: offender.file || null,
+                            line: offender.value.position ? offender.value.position.start.line : null,
+                            column: offender.value.position ? offender.value.position.start.column : null
                         };
                     }
 
-
                     debug('cssParsingErrors offenders transform function error with "%s"', offender);
                     return {
                         parseError: offender
@@ -971,7 +936,7 @@ var policies = {
             return offenders;
         }
     },
-    "unusedUnicodeRanges": {
+    /*"unusedUnicodeRanges": {
         "tool": "redownload",
         "label": "Unused Unicode ranges",
         "message": "<p>This metric counts the number of unused Unicode ranges inside each font. For example, one font could include Cyrillic glyphs but none of them are used on the page.</p><p>It also reveals the number of ligatures (letters that are represented differently when close to each other) and hidden chars (glyphs not linked to the unicode system that can't be displayed on the web).</p><p>Because of technical limitations, Yellow Lab Tools checks each font against the glyphs of the entire page. As a result, estimated use is >= to reality. For example, if you read that 10 glyphs are \"possibly used\", it means that these 10 glyphs are used on the page but nothing guaranties that they are displayed using this font.</p><p>Tools such as <a href=\"https://www.fontsquirrel.com/tools/webfont-generator\" target=\"_blank\">Font Squirrel</a> can remove some unicode ranges from a font.</p><p>In the case of an icon font, make sure you only keep the icons that are used on the website and to remove the others. Several tools are able to extract SVG images from a font, then some other tools can generate a font from the SVGs you want to keep.</p>",
@@ -982,7 +947,7 @@ var policies = {
         "offendersTransformFn": function(offenders) {
             return offenders;
         }
-    },
+    },*/
     "http2": {
         "label": "HTTP/2 or SPDY",
         "message": "<p>HTTP/2 is the latest version of the HTTP protocol and is designed to optimize load speed. SPDY is deprecated but still very well supported.</p><p>The latest versions of all major browsers are now compatible. The difficulty is on the server side, where technologies are not quite ready yet.</p>",

+ 1 - 2
lib/metadata/scoreProfileGeneric.json

@@ -82,8 +82,7 @@
             "label": "Web fonts",
             "policies": {
                 "fontsCount": 1,
-                "heavyFonts": 1,
-                "unusedUnicodeRanges": 1
+                "heavyFonts": 1
             }
         },
         "serverConfig": {