Skip to content

Commit b8ce516

Browse files
committed
add jscs style checker
* follow jscs node js style guide * better html template content insertion
1 parent ebd4263 commit b8ce516

File tree

4 files changed

+69
-21
lines changed

4 files changed

+69
-21
lines changed

config.jscs.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"disallowKeywords": [
3+
"with"
4+
],
5+
"disallowKeywordsOnNewLine": [
6+
"else"
7+
],
8+
"disallowMixedSpacesAndTabs": true,
9+
"disallowMultipleVarDecl": "exceptUndefined",
10+
"disallowNewlineBeforeBlockStatements": true,
11+
"disallowQuotedKeysInObjects": null,
12+
"disallowSpaceAfterObjectKeys": true,
13+
"disallowSpaceAfterPrefixUnaryOperators": true,
14+
"disallowSpacesInFunction": {
15+
"beforeOpeningRoundBrace": true
16+
},
17+
"disallowSpacesInsideParentheses": true,
18+
"disallowTrailingWhitespace": true,
19+
"maximumLineLength": 90,
20+
"requireCamelCaseOrUpperCaseIdentifiers": true,
21+
"requireCapitalizedComments": true,
22+
"requireCapitalizedConstructors": true,
23+
"requireCurlyBraces": true,
24+
"requireSpaceAfterKeywords": [
25+
"if",
26+
"else",
27+
"for",
28+
"while",
29+
"do",
30+
"switch",
31+
"case",
32+
"return",
33+
"try",
34+
"catch",
35+
"typeof"
36+
],
37+
"requireSpaceAfterLineComment": true,
38+
"requireSpaceAfterBinaryOperators": true,
39+
"requireSpaceBeforeBinaryOperators": true,
40+
"requireSpaceBeforeBlockStatements": true,
41+
"requireSpaceBeforeObjectValues": true,
42+
"requireSpacesInFunction": {
43+
"beforeOpeningCurlyBrace": true
44+
},
45+
"requireTrailingComma": null,
46+
"validateIndentation": 2,
47+
"validateLineBreaks": "LF",
48+
"validateQuoteMarks": "'"
49+
}

dist/template.html

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
-->
1111

1212
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/github.min.css">
13-
<style>
14-
{{css}}
15-
</style>
13+
<!--css-->
1614

1715
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>
1816
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/languages/scala.min.js"></script>
1917
<script>
20-
document.addEventListener("DOMContentLoaded", function () {
18+
document.addEventListener("DOMContentLoaded", function() {
2119
// collect all the distinct languages in the HTML
2220
var distinctLanguages = [];
23-
[].forEach.call(document.getElementsByClassName("d2h-file-wrapper"), function (file) {
21+
[].forEach.call(document.getElementsByClassName("d2h-file-wrapper"), function(file) {
2422
distinctLanguages.indexOf(file.dataset.lang) === -1 && distinctLanguages.push(file.dataset.lang);
2523
});
2624

@@ -29,7 +27,7 @@
2927

3028
// collect all the code lines and execute the highlight on them
3129
var codeLines = document.getElementsByClassName("d2h-code-line-ctn");
32-
[].forEach.call(codeLines, function (line) {
30+
[].forEach.call(codeLines, function(line) {
3331
hljs.highlightBlock(line);
3432
});
3533
});
@@ -39,7 +37,7 @@
3937
<h1>Diff to HTML by <a href="https://github.com/rtfpessoa">rtfpessoa</a></h1>
4038

4139
<div>
42-
{{diff}}
40+
<!--diff-->
4341
</div>
4442
</body>
4543
</html>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"main": "./src/main.js",
5454

5555
"dependencies": {
56-
"yargs": "3.17.*",
56+
"yargs": "3.18.*",
5757
"extend": "3.0.0",
5858
"diff2html": "*"
5959
},

src/main.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* diff2html CLI (main.js)
3+
* Diff to HTML CLI (main.js)
44
* Author: rtfpessoa
55
*
66
*/
@@ -66,11 +66,12 @@ var argv = require('yargs')
6666
}
6767
})
6868
.example('diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1',
69-
'diff last commit, line by line, word comparison between lines, previewed in the browser and input from git diff command')
69+
'diff last commit, line by line, word comparison between lines,' +
70+
'previewed in the browser and input from git diff command')
7071
.example('diff2html -i file -- my-file-diff.diff', 'reading the input from a file')
7172
.example('diff2html -f json -o stdout -- -M HEAD~1', 'print json format to stdout')
7273
.example('diff2html -F my-pretty-diff.html -- -M HEAD~1', 'print to file')
73-
.version(function () {
74+
.version(function() {
7475
return require('../package').version;
7576
})
7677
.help('h')
@@ -94,7 +95,7 @@ function main() {
9495
print(content);
9596
}
9697
} else {
97-
error("The input is empty. Try again.");
98+
error('The input is empty. Try again.');
9899
argv.help();
99100
}
100101

@@ -107,9 +108,9 @@ function getInput() {
107108
} else {
108109
var gitArgs;
109110
if (argv._.length && argv._[0]) {
110-
gitArgs = argv._.join(" ");
111+
gitArgs = argv._.join(' ');
111112
} else {
112-
gitArgs = "-M HEAD~1"
113+
gitArgs = '-M HEAD~1'
113114
}
114115

115116
var diffCommand = 'git diff ' + gitArgs;
@@ -139,17 +140,17 @@ function getOutput(input) {
139140
}
140141

141142
function preview(content) {
142-
var filePath = "/tmp/diff." + argv.format;
143+
var filePath = '/tmp/diff.' + argv.format;
143144
writeFile(filePath, content);
144-
runCmd("open " + filePath);
145+
runCmd('open ' + filePath);
145146
}
146147

147148
function prepareHTML(content) {
148-
var template = readFile(__dirname + "/../dist/template.html", "utf8");
149-
var css = readFile(__dirname + "/../dist/diff2html.css", "utf8");
149+
var template = readFile(__dirname + '/../dist/template.html', 'utf8');
150+
var css = readFile(__dirname + '/../dist/diff2html.css', 'utf8');
150151
return template
151-
.replace("{{css}}", css)
152-
.replace("{{diff}}", content);
152+
.replace('<!--css-->', '<style>\n' + css + '\n</style>')
153+
.replace('<!--diff-->', content);
153154
}
154155

155156
function prepareJSON(content) {
@@ -166,7 +167,7 @@ function error(msg) {
166167

167168
function readFile(filePath) {
168169
var fs = require('fs');
169-
return fs.readFileSync(filePath, "utf8");
170+
return fs.readFileSync(filePath, 'utf8');
170171
}
171172

172173
function writeFile(filePath, content) {

0 commit comments

Comments
 (0)