diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index 461f17f..abdd706 100644 --- a/lib/metadata/policies.js +++ b/lib/metadata/policies.js @@ -371,7 +371,7 @@ var policies = { }, "jQueryVersionsLoaded": { "tool": "phantomas", - "label": "Several versions loaded", + "label": "Several jQuery loaded", "message": "
jQuery is a heavy library. You should never load jQuery more than once on the same page.
", "isOkThreshold": 1, "isBadThreshold": 2, @@ -384,26 +384,48 @@ var policies = { "message": "Yellow Lab Tools failed to parse a CSS file. I doubt the problem comes from the css parser.
Maybe a CSS validator can help you.
", "isOkThreshold": 0, "isBadThreshold": 1, - "isAbnormalThreshold": 1, + "isAbnormalThreshold": 8, "hasOffenders": true, "offendersTransformFn": function(offenders) { return { count: offenders.length, list: offenders.map(function(offender) { - var parts = /^(?:(?:<([^ \(]*)>|\[inline CSS\]) ?)?(?:\((((?! @ ).)*)(?: @ (\d+):(\d+))?\))?$/.exec(offender); - - if (!parts) { - debug('cssParsingErrors offenders transform function error with "%s"', offender); + if (offender === '[inline CSS] (Empty CSS was provided)') { return { - parseError: offender + error: 'Empty style tag', + file: null, + line: null, + column: null }; } + 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) { + 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 { - error: parts[2], - file: parts[1] || null, - line: (parts[4] && parts[5]) ? parseInt(parts[4], 10) : null, - column: (parts[4] && parts[5]) ? parseInt(parts[5], 10) : null + parseError: offender }; }) }; diff --git a/lib/metadata/scoreProfileGeneric.json b/lib/metadata/scoreProfileGeneric.json index e1b4b57..319c83c 100644 --- a/lib/metadata/scoreProfileGeneric.json +++ b/lib/metadata/scoreProfileGeneric.json @@ -35,12 +35,6 @@ "jQueryVersionsLoaded": 0.1 } }, - "cssSyntaxError": { - "label": "CSS syntax errors", - "policies": { - "cssParsingErrors": 1 - } - }, "cssComplexity": { "label": "CSS complexity", "policies": { @@ -53,6 +47,7 @@ "badCSS": { "label": "Bad CSS", "policies": { + "cssParsingErrors": 4, "cssImports": 3, "cssDuplicatedSelectors": 2, "cssDuplicatedProperties": 1, diff --git a/package.json b/package.json index 68a51aa..7b03965 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "grunt-inline-angular-templates": "^0.1.5", "grunt-line-remover": "^0.0.2", "grunt-mocha-test": "^0.12.7", - "grunt-replace": "^0.9.1", + "grunt-replace": "^0.8.0", "grunt-usemin": "^3.0.0", "grunt-webfont": "^0.5.2", "matchdep": "^0.3.0",