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 037bc8a commit 9df3bae
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
12 changes: 11 additions & 1 deletion lib/checks/010-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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
2 changes: 2 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
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 9df3bae

Please sign in to comment.