Skip to content

Commit

Permalink
Fixed pushing correct file reference for errors/warnings
Browse files Browse the repository at this point in the history
no issue

- failures[..].ref is alwqys the target file reference
- ensure consistency
  • Loading branch information
kirrg001 committed Aug 9, 2018
1 parent 262f546 commit 24a5546
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
22 changes: 20 additions & 2 deletions lib/checks/010-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 7 additions & 2 deletions lib/checks/020-theme-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/checks/030-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`});
}
}

Expand Down
7 changes: 5 additions & 2 deletions lib/checks/040-ghost-head-foot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions test/010-package-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
4 changes: 4 additions & 0 deletions test/020-theme-structure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
5 changes: 3 additions & 2 deletions test/030-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/040-ghost-head-foot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 24a5546

Please sign in to comment.