Skip to content

Commit 594511f

Browse files
committed
Merge pull request #30 from escaton/issue_#26
fix #26
2 parents 2b0a4bd + fdbbe80 commit 594511f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

app/lib/collectData.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ function buildRuleInfo(rulePath) {
5454
var projectUrl = 'https://github.com/' + config.githubOrganization + '/' + config.githubProject;
5555
var blobUrl = projectUrl + '/blob/master';
5656
var fileUrl = blobUrl + '/lib/rules/' + filename;
57+
var testFilePath = buildRuleTestFilePath(filename);
5758
var testUrl = blobUrl + '/test/specs/rules/' + filename;
5859

59-
return vowFs.read(rulePath, 'utf8').then(function(fileContents) {
60+
return vow.all([vowFs.read(rulePath, 'utf8'), vowFs.exists(testFilePath)]).spread(function(fileContents, hasTestFile) {
6061
var match = fileContents.match(/^\/\*\*([\s\S]*?)\*\//m);
6162
var description = '';
6263
if (match) {
@@ -84,12 +85,17 @@ function buildRuleInfo(rulePath) {
8485
description: description,
8586
shortDescription: shortDescription,
8687
sourceUrl: fileUrl,
88+
renderTestLink: hasTestFile,
8789
testUrl: testUrl,
8890
filename: filename
8991
});
9092
});
9193
}
9294

95+
function buildRuleTestFilePath(ruleFilename) {
96+
return jscsRoot + '/test/specs/rules/' + ruleFilename;
97+
}
98+
9399
function getAvailableRules() {
94100
var rulesDir = jscsRoot + '/lib/rules';
95101
return vowFs.listDir(rulesDir).then(function(filenames) {

app/models/RuleModel.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class RuleModel {
44
this._description = data.description;
55
this._shortDescription = data.shortDescription;
66
this._sourceUrl = data.sourceUrl;
7+
this._renderTestLink = data.renderTestLink;
78
this._testUrl = data.testUrl;
89
this._filename = data.filename;
910
}
@@ -24,6 +25,10 @@ class RuleModel {
2425
return this._sourceUrl;
2526
}
2627

28+
getRenderTestLink() {
29+
return this._renderTestLink;
30+
}
31+
2732
getTestUrl() {
2833
return this._testUrl;
2934
}
@@ -38,7 +43,9 @@ class RuleModel {
3843
description: this._description,
3944
shortDescription: this._shortDescription,
4045
sourceUrl: this._sourceUrl,
41-
testUrl: this._testUrl
46+
renderTestLink: this._renderTestLink,
47+
testUrl: this._testUrl,
48+
filename: this._filename
4249
};
4350
}
4451
}

app/views/pages/RulePageView/index.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ export default React.createClass({
3737
</div>
3838
</div>
3939
<div><a href={rule.getSourceUrl()}>Rule source</a></div>
40-
<div><a href={rule.getTestUrl()}>Test source</a></div>
40+
{(() => {
41+
if (rule.getRenderTestLink()) {
42+
return (
43+
<div><a href={rule.getTestUrl()}>Test source</a></div>
44+
)
45+
}
46+
})()}
4147
</PageView>
4248
)
4349
}

0 commit comments

Comments
 (0)