Skip to content

Commit 8d86a15

Browse files
committed
Clean code and force code style
Since more people are contributing to the code Codacy will help keep it consistent and easy to maintain, by suggesting improvements
1 parent 4d3d752 commit 8d86a15

File tree

11 files changed

+559
-481
lines changed

11 files changed

+559
-481
lines changed

dist/diff2html.js

Lines changed: 280 additions & 238 deletions
Large diffs are not rendered by default.

dist/diff2html.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/diff-parser.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
(function(ctx, undefined) {
8+
(function() {
99

1010
var utils = require('./utils.js').Utils;
1111

@@ -31,6 +31,7 @@
3131
var newLine = null;
3232

3333
var saveBlock = function() {
34+
3435
/* Add previous block(if exists) before start a new file */
3536
if (currentBlock) {
3637
currentFile.blocks.push(currentBlock);
@@ -39,6 +40,7 @@
3940
};
4041

4142
var saveFile = function() {
43+
4244
/*
4345
* Add previous file(if exists) before start a new one
4446
* if it has name (to avoid binary files errors)
@@ -216,11 +218,11 @@
216218
var nameSplit = filename.split('.');
217219
if (nameSplit.length > 1) {
218220
return nameSplit[nameSplit.length - 1];
219-
} else {
220-
return language;
221221
}
222+
223+
return language;
222224
}
223225

224-
module.exports['DiffParser'] = new DiffParser();
226+
module.exports.DiffParser = new DiffParser();
225227

226-
})(this);
228+
})();

src/diff2html.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
(function(ctx, undefined) {
8+
(function() {
99

1010
var diffParser = require('./diff-parser.js').DiffParser;
1111
var fileLister = require('./file-list-printer.js').FileListPrinter;
@@ -17,9 +17,9 @@
1717
/*
1818
* Line diff type configuration
1919
var config = {
20-
"wordByWord": true, // (default)
20+
'wordByWord': true, // (default)
2121
// OR
22-
"charByChar": true
22+
'charByChar': true
2323
};
2424
*/
2525

@@ -37,23 +37,23 @@
3737
var configOrEmpty = config || {};
3838

3939
var diffJson = diffInput;
40-
if(!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') {
40+
if (!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') {
4141
diffJson = diffParser.generateDiffJson(diffInput);
4242
}
4343

44-
var fileList = "";
45-
if(configOrEmpty.showFiles === true) {
44+
var fileList = '';
45+
if (configOrEmpty.showFiles === true) {
4646
fileList = fileLister.generateFileList(diffJson, configOrEmpty);
4747
}
4848

49-
var diffOutput = "";
50-
if(configOrEmpty.outputFormat === 'side-by-side') {
49+
var diffOutput = '';
50+
if (configOrEmpty.outputFormat === 'side-by-side') {
5151
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
5252
} else {
5353
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
5454
}
5555

56-
return fileList + diffOutput
56+
return fileList + diffOutput;
5757
};
5858

5959

@@ -66,45 +66,45 @@
6666
*/
6767
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
6868
var configOrEmpty = config || {};
69-
configOrEmpty['inputFormat'] = 'diff';
70-
configOrEmpty['outputFormat'] = 'line-by-line';
71-
return this.getPrettyHtml(diffInput, configOrEmpty)
69+
configOrEmpty.inputFormat = 'diff';
70+
configOrEmpty.outputFormat = 'line-by-line';
71+
return this.getPrettyHtml(diffInput, configOrEmpty);
7272
};
7373

7474
/*
7575
* Generates pretty html from a json object
7676
*/
7777
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
7878
var configOrEmpty = config || {};
79-
configOrEmpty['inputFormat'] = 'json';
80-
configOrEmpty['outputFormat'] = 'line-by-line';
81-
return this.getPrettyHtml(diffJson, configOrEmpty)
79+
configOrEmpty.inputFormat = 'json';
80+
configOrEmpty.outputFormat = 'line-by-line';
81+
return this.getPrettyHtml(diffJson, configOrEmpty);
8282
};
8383

8484
/*
8585
* Generates pretty side by side html from string diff input
8686
*/
8787
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
8888
var configOrEmpty = config || {};
89-
configOrEmpty['inputFormat'] = 'diff';
90-
configOrEmpty['outputFormat'] = 'side-by-side';
91-
return this.getPrettyHtml(diffInput, configOrEmpty)
89+
configOrEmpty.inputFormat = 'diff';
90+
configOrEmpty.outputFormat = 'side-by-side';
91+
return this.getPrettyHtml(diffInput, configOrEmpty);
9292
};
9393

9494
/*
9595
* Generates pretty side by side html from a json object
9696
*/
9797
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
9898
var configOrEmpty = config || {};
99-
configOrEmpty['inputFormat'] = 'json';
100-
configOrEmpty['outputFormat'] = 'side-by-side';
101-
return this.getPrettyHtml(diffJson, configOrEmpty)
99+
configOrEmpty.inputFormat = 'json';
100+
configOrEmpty.outputFormat = 'side-by-side';
101+
return this.getPrettyHtml(diffJson, configOrEmpty);
102102
};
103103

104-
var diffName = 'Diff2Html';
105104
var diffObject = new Diff2Html();
106-
module.exports[diffName] = diffObject;
105+
module.exports.Diff2Html = diffObject;
106+
107107
// Expose diff2html in the browser
108-
global[diffName] = diffObject;
108+
global.Diff2Html = diffObject;
109109

110-
})(this);
110+
})();

src/file-list-printer.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@
55
*
66
*/
77

8-
(function (ctx, undefined) {
9-
10-
var printerUtils = require('./printer-utils.js').PrinterUtils;
11-
var utils = require('./utils.js').Utils;
12-
13-
function FileListPrinter() {
14-
}
15-
16-
FileListPrinter.prototype.generateFileList = function (diffFiles) {
17-
var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page
18-
var showId = utils.getRandomId("d2h-show");
19-
return '<div class="d2h-file-list-wrapper">\n' +
20-
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' +
21-
' <a id="' + hideId + '" class="d2h-hide" href="#' + hideId + '">+</a>\n' +
22-
' <a id="' + showId + 'd2h-show" class="d2h-show" href="#' + showId + '">-</a>\n' +
23-
' <div class="d2h-clear"></div>\n' +
24-
' <table class="d2h-file-list">\n' +
25-
26-
27-
diffFiles.map(function (file) {
28-
return ' <tr class="d2h-file-list-line">\n' +
29-
' <td class="d2h-lines-added">\n' +
30-
' <span>+' + file.addedLines + '</span>\n' +
31-
' </td>\n' +
32-
' <td class="d2h-lines-deleted">\n' +
33-
' <span>-' + file.deletedLines + '</span>\n' +
34-
' </td>\n' +
35-
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '">&nbsp;' + printerUtils.getDiffName(file) + '</a></td>\n' +
36-
' </tr>\n'
37-
}).join('\n') +
38-
'</table></div>\n';
39-
};
40-
41-
module.exports['FileListPrinter'] = new FileListPrinter();
42-
43-
})(this);
8+
(function() {
9+
10+
var printerUtils = require('./printer-utils.js').PrinterUtils;
11+
var utils = require('./utils.js').Utils;
12+
13+
function FileListPrinter() {
14+
}
15+
16+
FileListPrinter.prototype.generateFileList = function(diffFiles) {
17+
var hideId = utils.getRandomId('d2h-hide'); //necessary if there are 2 elements like this in the same page
18+
var showId = utils.getRandomId('d2h-show');
19+
return '<div class="d2h-file-list-wrapper">\n' +
20+
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' +
21+
' <a id="' + hideId + '" class="d2h-hide" href="#' + hideId + '">+</a>\n' +
22+
' <a id="' + showId + 'd2h-show" class="d2h-show" href="#' + showId + '">-</a>\n' +
23+
' <div class="d2h-clear"></div>\n' +
24+
' <table class="d2h-file-list">\n' +
25+
26+
27+
diffFiles.map(function(file) {
28+
return ' <tr class="d2h-file-list-line">\n' +
29+
' <td class="d2h-lines-added">\n' +
30+
' <span>+' + file.addedLines + '</span>\n' +
31+
' </td>\n' +
32+
' <td class="d2h-lines-deleted">\n' +
33+
' <span>-' + file.deletedLines + '</span>\n' +
34+
' </td>\n' +
35+
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '">&nbsp;' + printerUtils.getDiffName(file) + '</a></td>\n' +
36+
' </tr>\n';
37+
}).join('\n') +
38+
'</table></div>\n';
39+
};
40+
41+
module.exports.FileListPrinter = new FileListPrinter();
42+
43+
})();

src/html-printer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
(function(ctx, undefined) {
8+
(function() {
99

1010
var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
1111
var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;
@@ -20,6 +20,6 @@
2020

2121
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
2222

23-
module.exports['HtmlPrinter'] = new HtmlPrinter();
23+
module.exports.HtmlPrinter = new HtmlPrinter();
2424

25-
})(this);
25+
})();

0 commit comments

Comments
 (0)