diff --git a/config.jscs.json b/.jscsrc similarity index 86% rename from config.jscs.json rename to .jscsrc index 17dec03..03eb9b2 100644 --- a/config.jscs.json +++ b/.jscsrc @@ -6,9 +6,12 @@ "else" ], "disallowMixedSpacesAndTabs": true, - "disallowMultipleVarDecl": "exceptUndefined", + "disallowMultipleVarDecl": { + "allExcept": [ + "undefined" + ] + }, "disallowNewlineBeforeBlockStatements": true, - "disallowQuotedKeysInObjects": true, "disallowSpaceAfterObjectKeys": true, "disallowSpaceAfterPrefixUnaryOperators": true, "disallowSpacesInFunction": { @@ -16,7 +19,7 @@ }, "disallowSpacesInsideParentheses": true, "disallowTrailingWhitespace": true, - "maximumLineLength": 120, + "maximumLineLength": 130, "requireCamelCaseOrUpperCaseIdentifiers": true, "requireCapitalizedComments": true, "requireCapitalizedConstructors": true, @@ -44,6 +47,5 @@ }, "requireTrailingComma": null, "validateIndentation": 2, - "validateLineBreaks": "LF", - "validateQuoteMarks": "'" + "validateLineBreaks": "LF" } diff --git a/src/file-list-printer.js b/src/file-list-printer.js index 493e1b0..da20000 100644 --- a/src/file-list-printer.js +++ b/src/file-list-printer.js @@ -14,7 +14,7 @@ } FileListPrinter.prototype.generateFileList = function(diffFiles) { - var hideId = utils.getRandomId('d2h-hide'); //necessary if there are 2 elements like this in the same page + var hideId = utils.getRandomId('d2h-hide'); // Necessary if there are 2 elements like this in the same page var showId = utils.getRandomId('d2h-show'); return '
\n' + '
Files changed (' + diffFiles.length + ')  
\n' + @@ -32,7 +32,8 @@ ' \n' + ' -' + file.deletedLines + '\n' + ' \n' + - '  ' + printerUtils.getDiffName(file) + '\n' + + ' ' + + ' ' + printerUtils.getDiffName(file) + '\n' + ' \n'; }).join('\n') + '
\n'; diff --git a/src/printer-utils.js b/src/printer-utils.js index d22cb58..74de635 100644 --- a/src/printer-utils.js +++ b/src/printer-utils.js @@ -19,7 +19,9 @@ var i, chr, len; var hash = 0; - if (text.length === 0) return hash; + if (text.length === 0) { + return hash; + } for (i = 0, len = text.length; i < len; i++) { chr = text.charCodeAt(i); @@ -75,7 +77,7 @@ if (!config.charByChar && config.matching === 'words') { var treshold = 0.25; - if (typeof(config.matchWordsThreshold) !== 'undefined') { + if (typeof (config.matchWordsThreshold) !== 'undefined') { treshold = config.matchWordsThreshold; } diff --git a/src/rematch.js b/src/rematch.js index 912cfc7..32b22b5 100644 --- a/src/rematch.js +++ b/src/rematch.js @@ -19,23 +19,33 @@ /* Copyright (c) 2011 Andrei Mackenzie - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + documentation files (the "Software"), to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ function levenshtein(a, b) { - if (a.length == 0) return b.length; - if (b.length == 0) return a.length; + if (a.length == 0) { + return b.length; + } + if (b.length == 0) { + return a.length; + } var matrix = []; - // increment along the first column of each row + // Increment along the first column of each row var i; for (i = 0; i <= b.length; i++) { matrix[i] = [i]; } - // increment each column in the first row + // Increment each column in the first row var j; for (j = 0; j <= a.length; j++) { matrix[0][j] = j; @@ -47,9 +57,9 @@ if (b.charAt(i - 1) == a.charAt(j - 1)) { matrix[i][j] = matrix[i - 1][j - 1]; } else { - matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution - Math.min(matrix[i][j - 1] + 1, // insertion - matrix[i - 1][j] + 1)); // deletion + matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // Substitution + Math.min(matrix[i][j - 1] + 1, // Insertion + matrix[i - 1][j] + 1)); // Deletion } } } @@ -99,7 +109,7 @@ } function group(a, b, level, cache) { - if (typeof(cache) === "undefined") { + if (typeof (cache) === "undefined") { cache = {}; } @@ -113,14 +123,14 @@ return [[a, b]]; } - var a1 = a.slice(0, bm.indexA), - b1 = b.slice(0, bm.indexB), - aMatch = [a[bm.indexA]], - bMatch = [b[bm.indexB]], - tailA = bm.indexA + 1, - tailB = bm.indexB + 1, - a2 = a.slice(tailA), - b2 = b.slice(tailB); + var a1 = a.slice(0, bm.indexA); + var b1 = b.slice(0, bm.indexB); + var aMatch = [a[bm.indexA]]; + var bMatch = [b[bm.indexB]]; + var tailA = bm.indexA + 1; + var tailB = bm.indexB + 1; + var a2 = a.slice(tailA); + var b2 = b.slice(tailB); var group1 = group(a1, b1, level + 1, cache); var groupMatch = group(aMatch, bMatch, level + 1, cache); diff --git a/src/side-by-side-printer.js b/src/side-by-side-printer.js index 5002452..485eafc 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -12,6 +12,13 @@ var utils = require('./utils.js').Utils; var Rematch = require('./rematch.js').Rematch; + var matcher = Rematch.rematch(function(a, b) { + var amod = a.content.substr(1); + var bmod = b.content.substr(1); + + return Rematch.distance(amod, bmod); + }); + function SideBySidePrinter(config) { this.config = config; } @@ -65,12 +72,6 @@ '\n'; }; - var matcher = Rematch.rematch(function(a, b) { - var amod = a.content.substr(1), - bmod = b.content.substr(1); - return Rematch.distance(amod, bmod); - }); - SideBySidePrinter.prototype.generateSideBySideFileHtml = function(file) { var that = this; var fileHtml = {}; diff --git a/test/diff2html-tests.js b/test/diff2html-tests.js index 5e33112..9de7412 100644 --- a/test/diff2html-tests.js +++ b/test/diff2html-tests.js @@ -6,12 +6,12 @@ describe('Diff2Html', function() { describe('getJsonFromDiff', function() { it('should parse simple diff to json', function() { var diff = - 'diff --git a/sample b/sample\n'+ - 'index 0000001..0ddf2ba\n'+ - '--- a/sample\n'+ - '+++ b/sample\n'+ - '@@ -1 +1 @@\n'+ - '-test\n'+ + 'diff --git a/sample b/sample\n' + + 'index 0000001..0ddf2ba\n' + + '--- a/sample\n' + + '+++ b/sample\n' + + '@@ -1 +1 @@\n' + + '-test\n' + '+test1\n'; var result = Diff2Html.getJsonFromDiff(diff); var file1 = result[0]; diff --git a/test/side-by-side-printer-tests.js b/test/side-by-side-printer-tests.js index 6821865..87128bd 100644 --- a/test/side-by-side-printer-tests.js +++ b/test/side-by-side-printer-tests.js @@ -105,15 +105,19 @@ describe('SideBySidePrinter', function() { var HTMLParser = require('fast-html-parser'); + var prefixTag = '.d2h-code-line-prefix'; + var parsedExpectedRight = HTMLParser.parse(expectedRight); var parsedFileRight = HTMLParser.parse(fileHtml.right); - assert.equal(parsedExpectedRight.querySelectorAll(".d2h-code-line-prefix").length > 0, true); - assert.equal(parsedExpectedRight.querySelectorAll(".d2h-code-line-prefix").length, parsedFileRight.querySelectorAll(".d2h-code-line-prefix").length); + assert.equal(parsedExpectedRight.querySelectorAll(prefixTag).length > 0, true); + assert.equal(parsedExpectedRight.querySelectorAll(prefixTag).length, + parsedFileRight.querySelectorAll(prefixTag).length); var parsedExpectedLeft = HTMLParser.parse(expectedLeft); var parsedFileLeft = HTMLParser.parse(fileHtml.left); - assert.equal(parsedExpectedLeft.querySelectorAll(".d2h-code-line-prefix").length > 0, true); - assert.equal(parsedExpectedLeft.querySelectorAll(".d2h-code-line-prefix").length, parsedFileLeft.querySelectorAll(".d2h-code-line-prefix").length); + assert.equal(parsedExpectedLeft.querySelectorAll(prefixTag).length > 0, true); + assert.equal(parsedExpectedLeft.querySelectorAll(prefixTag).length, + parsedFileLeft.querySelectorAll(prefixTag).length); }); }); });