From 6e6285c5ae46ede155052ab7557889befb23eac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 10 Aug 2020 13:56:37 +0200 Subject: [PATCH] Various adaptations for Phantomas v2 --- front/src/views/rule.html | 8 ++-- lib/metadata/policies.js | 53 +++++---------------------- lib/metadata/scoreProfileGeneric.json | 3 +- 3 files changed, 14 insertions(+), 50 deletions(-) diff --git a/front/src/views/rule.html b/front/src/views/rule.html index 2577dbe..58a3c30 100644 --- a/front/src/views/rule.html +++ b/front/src/views/rule.html @@ -45,7 +45,7 @@
- {{offender.id}}: {{offender.occurrences}} occurrences + {{offender.id}}: {{offender.count}} occurrences
@@ -123,7 +123,7 @@
- {{offender.property}} {{offender.message}} + {{offender.property}} {{offender.message}}
show hide @@ -183,8 +183,8 @@

in - - inline CSS + + inline CSS

diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index aca3af8..1239547 100644 --- a/lib/metadata/policies.js +++ b/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) { + if (offender.value) { 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 + 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 }; } - // Try another syntax - parts = /^(.*) <(.*)> @ (\d+):(\d+)$/.exec(offender); - - if (parts) { - return { - error: parts[1] || 'Unknown parsing error', - file: parts[2] || null, - line: parseInt(parts[3], 10), - column: parseInt(parts[4], 10) - }; - } - - 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": "

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.

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).

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.

Tools such as Font Squirrel can remove some unicode ranges from a font.

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.

", @@ -982,7 +947,7 @@ var policies = { "offendersTransformFn": function(offenders) { return offenders; } - }, + },*/ "http2": { "label": "HTTP/2 or SPDY", "message": "

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.

The latest versions of all major browsers are now compatible. The difficulty is on the server side, where technologies are not quite ready yet.

", diff --git a/lib/metadata/scoreProfileGeneric.json b/lib/metadata/scoreProfileGeneric.json index b4f75e7..5646b26 100644 --- a/lib/metadata/scoreProfileGeneric.json +++ b/lib/metadata/scoreProfileGeneric.json @@ -82,8 +82,7 @@ "label": "Web fonts", "policies": { "fontsCount": 1, - "heavyFonts": 1, - "unusedUnicodeRanges": 1 + "heavyFonts": 1 } }, "serverConfig": {