Skip to content

Commit

Permalink
chore: fix jshint
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Jun 17, 2015
1 parent af82c2b commit 1d149c8
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 80 deletions.
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module.exports = function (grunt) {
},

jshint: {
options: {
jshintrc: '.jshintrc'
},
files: [
'Gruntfile.js',
'src/**/*.js',
Expand Down
4 changes: 2 additions & 2 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/subParsers/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ showdown.subParser('lists', function (text, options, globals) {
var txt = results[i].slice(2),
nListType = results[i].slice(0, 2);

if (listType != nListType) {
if (listType !== nListType) {
y++;
holder[y] = [];
holder[y].type = nListType;
Expand Down
150 changes: 79 additions & 71 deletions test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,95 @@
*/

//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
require('source-map-support').install();
require('chai').should();
var fs = require('fs'),
(function () {
'use strict';

require('source-map-support').install();
require('chai').should();
var fs = require('fs'),
os = require('os'),
/*jshint -W106 */
beautify = require('js-beautify').html_beautify,
beauOptions = {
eol: os.EOL,
indent_size: 2,
preserve_newlines: false
};
/*jshint +W106 */

function getTestSuite(dir) {
return fs.readdirSync(dir)
.filter(filter())
.map(map(dir));
}
function getTestSuite(dir) {
return fs.readdirSync(dir)
.filter(filter())
.map(map(dir));
}

function filter() {
return function (file) {
var ext = file.slice(-3);
return (ext === '.md');
};
}

function map(dir) {
return function (file) {
var name = file.replace('.md', ''),
htmlPath = dir + name + '.html',
html = fs.readFileSync(htmlPath, 'utf8'),
mdPath = dir + name + '.md',
md = fs.readFileSync(mdPath, 'utf8');

return {
name: name,
input: md,
expected: html
function filter() {
return function (file) {
var ext = file.slice(-3);
return (ext === '.md');
};
};
}
}

function map(dir) {
return function (file) {
var name = file.replace('.md', ''),
htmlPath = dir + name + '.html',
html = fs.readFileSync(htmlPath, 'utf8'),
mdPath = dir + name + '.md',
md = fs.readFileSync(mdPath, 'utf8');

return {
name: name,
input: md,
expected: html
};
};
}

function assertion(testCase, converter) {
return function () {
testCase.actual = converter.makeHtml(testCase.input);
testCase = normalize(testCase);

// Compare
testCase.actual.should.equal(testCase.expected);
};
}

//Normalize input/output
function normalize(testCase) {

// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');

// Ignore all leading/trailing whitespace
testCase.expected = testCase.expected.split('\n').map(function (x) {
return x.trim();
}).join('\n');
testCase.actual = testCase.actual.split('\n').map(function (x) {
return x.trim();
}).join('\n');

function assertion(testCase, converter) {
return function () {
testCase.actual = converter.makeHtml(testCase.input);
testCase = normalize(testCase);
// Remove extra lines
testCase.expected = testCase.expected.trim();
testCase.actual = testCase.actual.trim();

// Compare
testCase.actual.should.equal(testCase.expected);
//Beautify
testCase.expected = beautify(testCase.expected, beauOptions);
testCase.actual = beautify(testCase.actual, beauOptions);

// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, os.EOL);
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, os.EOL);

return testCase;
}

module.exports = {
getTestSuite: getTestSuite,
assertion: assertion,
normalize: normalize,
};
}

//Normalize input/output
function normalize(testCase) {

// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');

// Ignore all leading/trailing whitespace
testCase.expected = testCase.expected.split('\n').map(function (x) {
return x.trim();
}).join('\n');
testCase.actual = testCase.actual.split('\n').map(function (x) {
return x.trim();
}).join('\n');

// Remove extra lines
testCase.expected = testCase.expected.trim();
testCase.actual = testCase.actual.trim();

//Beautify
testCase.expected = beautify(testCase.expected, beauOptions);
testCase.actual = beautify(testCase.actual, beauOptions);

// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, os.EOL);
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, os.EOL);

return testCase;
}

module.exports = {
getTestSuite: getTestSuite,
assertion: assertion
};
})();

2 changes: 1 addition & 1 deletion test/node/testsuite.issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var showdown = require('../../dist/showdown.js'),
assertion = bootstrap.assertion,
testsuite = bootstrap.getTestSuite('test/issues/');

//MD-Testsuite (borrowed from karlcow/markdown-testsuite)
describe('makeHtml() issues testsuite', function () {
'use strict';
for (var i = 0; i < testsuite.length; ++i) {
it(testsuite[i].name, assertion(testsuite[i], converter));
}
Expand Down
1 change: 1 addition & 0 deletions test/node/testsuite.karlcow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var showdown = require('../../dist/showdown.js'),

//MD-Testsuite (borrowed from karlcow/markdown-testsuite)
describe('makeHtml() karlcow testsuite', function () {
'use strict';
for (var i = 0; i < testsuite.length; ++i) {
it(testsuite[i].name, assertion(testsuite[i], converter));
}
Expand Down
2 changes: 1 addition & 1 deletion test/node/testsuite.standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var showdown = require('../../dist/showdown.js'),
assertion = bootstrap.assertion,
testsuite = bootstrap.getTestSuite('test/cases/');

//MD-Testsuite (borrowed from karlcow/markdown-testsuite)
describe('makeHtml() standard testsuite', function () {
'use strict';
for (var i = 0; i < testsuite.length; ++i) {
it(testsuite[i].name, assertion(testsuite[i], converter));
}
Expand Down

0 comments on commit 1d149c8

Please sign in to comment.