From 437c99f72cd6c350ffe1388f2a95a405637592cf Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Wed, 8 Aug 2018 21:41:21 +0200 Subject: [PATCH] Fixed pushing correct file reference for errors/warnings no issue - failures[..].ref is always the target file reference - ensure consistency --- lib/checks/010-package-json.js | 22 ++++++++++++++++++++-- lib/checks/020-theme-structure.js | 9 +++++++-- lib/checks/030-assets.js | 4 ++-- lib/checks/040-ghost-head-foot.js | 7 +++++-- test/010-package-json.test.js | 5 +++++ test/020-theme-structure.test.js | 4 ++++ test/030-assets.test.js | 5 +++-- test/040-ghost-head-foot.test.js | 3 +++ 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/lib/checks/010-package-json.js b/lib/checks/010-package-json.js index feff022c..8790bbec 100644 --- a/lib/checks/010-package-json.js +++ b/lib/checks/010-package-json.js @@ -71,7 +71,15 @@ _private.validatePackageJSONFields = function validatePackageJSONFields(packageJ failed.push(packageJSONValidationRules.authorEmailIsValid); } - _.extend(theme.results.fail, _private.getFailedRules(failed)); + const failedRules = _private.getFailedRules(failed); + _.each(failedRules, (rule, key) => { + theme.results.fail[key] = {}; + theme.results.fail[key].failures = [ + { + ref: 'package.json' + } + ]; + }); // add intersection as passed theme.results.pass = theme.results.pass.concat(_.xor(failed, _.values(_.omit(packageJSONValidationRules, passedRulesToOmit)))); @@ -99,7 +107,17 @@ module.exports = function checkPackageJSON(theme, options) { // CASE: package.json must be present (if not, all validation rules fail) if (!_.some(theme.files, {file: packageJSONFile})) { - _.extend(theme.results.fail, _private.getFailedRules(_.values(_.omit(packageJSONValidationRules, _.keys(packageJSONConditionalRules))))); + const rules = _private.getFailedRules(_.values(_.omit(packageJSONValidationRules, _.keys(packageJSONConditionalRules)))); + + _.each(rules, (rule, key) => { + theme.results.fail[key] = {}; + theme.results.fail[key].failures = [ + { + ref: 'package.json' + } + ]; + }); + return theme; } diff --git a/lib/checks/020-theme-structure.js b/lib/checks/020-theme-structure.js index 0e77ac91..6ee2ebb3 100644 --- a/lib/checks/020-theme-structure.js +++ b/lib/checks/020-theme-structure.js @@ -26,7 +26,6 @@ const latestRulesToCheck = []; checkThemeStructure = function checkThemeStructure(theme, options) { const checkVersion = _.get(options, 'checkVersion', 'latest'); const ruleSet = spec.get([checkVersion]); - const rulesToCheck = checkVersion === 'v1' ? v1RulesToCheck : _.union(v1RulesToCheck, latestRulesToCheck); _.each(rulesToCheck, function (ruleCode) { @@ -39,7 +38,13 @@ checkThemeStructure = function checkThemeStructure(theme, options) { if (!_.some(theme.files, {file: check.path})) { // file doesn't exist - theme.results.fail[ruleCode] = {}; + theme.results.fail[ruleCode] = { + failures: [ + { + ref: check.path + } + ] + }; } else { theme.results.pass.push(ruleCode); } diff --git a/lib/checks/030-assets.js b/lib/checks/030-assets.js index a16d7780..ea8d89e1 100644 --- a/lib/checks/030-assets.js +++ b/lib/checks/030-assets.js @@ -13,13 +13,13 @@ checkAssets = function checkAssets(theme, options, themePath) { let ruleToCheck = 'GS030-ASSET-REQ'; let failures = []; let defaultHbs = _.filter(theme.files, {file: 'default.hbs'}); - let assetMatch; + let assetMatch; let stats; if (!_.isEmpty(defaultHbs)) { defaultHbs = defaultHbs[0]; while ((assetMatch = ruleSet.rules[ruleToCheck].regex.exec(defaultHbs.content)) !== null) { - failures.push({ref: assetMatch[2]}); + failures.push({ref: 'default.hbs', message: `${assetMatch[2]}`}); } } diff --git a/lib/checks/040-ghost-head-foot.js b/lib/checks/040-ghost-head-foot.js index 4e8d6cef..63851f7f 100644 --- a/lib/checks/040-ghost-head-foot.js +++ b/lib/checks/040-ghost-head-foot.js @@ -11,7 +11,6 @@ const latestRulesToCheck = []; checkGhostHeadFoot = function checkGhostHeadFoot(theme, options) { const checkVersion = _.get(options, 'checkVersion', 'latest'); const ruleSet = spec.get([checkVersion]); - const rulesToCheck = checkVersion === 'v1' ? v1RulesToCheck : _.union(v1RulesToCheck, latestRulesToCheck); _.each(rulesToCheck, function (ruleCode) { @@ -23,7 +22,11 @@ checkGhostHeadFoot = function checkGhostHeadFoot(theme, options) { } if (!theme.helpers || !theme.helpers.hasOwnProperty(check.helper)) { - theme.results.fail[ruleCode] = {}; + theme.results.fail[ruleCode] = { + failures: [{ + ref: 'default.hbs' + }] + }; } else { theme.results.pass.push(ruleCode); } diff --git a/test/010-package-json.test.js b/test/010-package-json.test.js index e9793dac..233ee54c 100644 --- a/test/010-package-json.test.js +++ b/test/010-package-json.test.js @@ -26,6 +26,7 @@ describe('010: package.json', function () { ); output.results.fail['GS010-PJ-REQ'].should.be.a.ValidFailObject(); + output.results.fail['GS010-PJ-REQ'].failures[0].ref.should.eql('package.json'); done(); }).catch(done); }); @@ -51,6 +52,7 @@ describe('010: package.json', function () { ); output.results.fail['GS010-PJ-REQ'].should.be.a.ValidFailObject(); + output.results.fail['GS010-PJ-REQ'].failures[0].ref.should.eql('package.json'); done(); }).catch(done); }); @@ -126,6 +128,9 @@ describe('010: package.json', function () { 'GS010-PJ-AUT-EM-VAL', 'GS010-PJ-CONF-PPP-INT' ); + + theme.results.fail['GS010-PJ-NAME-LC'].failures[0].ref.should.eql('package.json'); + done(); }).catch(done); }); diff --git a/test/020-theme-structure.test.js b/test/020-theme-structure.test.js index 87cf1af2..88aabb7f 100644 --- a/test/020-theme-structure.test.js +++ b/test/020-theme-structure.test.js @@ -18,6 +18,10 @@ describe('Theme structure', function () { output.results.fail['GS020-POST-REQ'].should.be.a.ValidFailObject(); output.results.fail['GS020-DEF-REC'].should.be.a.ValidFailObject(); + output.results.fail['GS020-INDEX-REQ'].failures[0].ref.should.eql('index.hbs'); + output.results.fail['GS020-POST-REQ'].failures[0].ref.should.eql('post.hbs'); + output.results.fail['GS020-DEF-REC'].failures[0].ref.should.eql('default.hbs'); + done(); }); }); diff --git a/test/030-assets.test.js b/test/030-assets.test.js index f5cd5b5a..65267540 100644 --- a/test/030-assets.test.js +++ b/test/030-assets.test.js @@ -16,8 +16,9 @@ describe('Assets', function () { output.results.fail['GS030-ASSET-REQ'].should.be.a.ValidFailObject(); output.results.fail['GS030-ASSET-REQ'].failures.should.be.an.Array().with.lengthOf(1); - output.results.fail['GS030-ASSET-REQ'].failures[0].should.have.keys('ref'); - output.results.fail['GS030-ASSET-REQ'].failures[0].ref.should.eql('/assets/css/style.css'); + output.results.fail['GS030-ASSET-REQ'].failures[0].should.have.keys('ref', 'message'); + output.results.fail['GS030-ASSET-REQ'].failures[0].ref.should.eql('default.hbs'); + output.results.fail['GS030-ASSET-REQ'].failures[0].message.should.eql('/assets/css/style.css'); done(); }).catch(done); diff --git a/test/040-ghost-head-foot.test.js b/test/040-ghost-head-foot.test.js index 1fd46b83..bd869048 100644 --- a/test/040-ghost-head-foot.test.js +++ b/test/040-ghost-head-foot.test.js @@ -16,6 +16,9 @@ describe('Ghost head & foot', function () { output.results.fail['GS040-GH-REQ'].should.be.a.ValidFailObject(); output.results.fail['GS040-GF-REQ'].should.be.a.ValidFailObject(); + output.results.fail['GS040-GH-REQ'].failures[0].ref.should.eql('default.hbs'); + output.results.fail['GS040-GF-REQ'].failures[0].ref.should.eql('default.hbs'); + done(); }).catch(done); });