Skip to content

Commit

Permalink
add jscs style checker
Browse files Browse the repository at this point in the history
* follow jscs node js style guide
* better html template content insertion
  • Loading branch information
rtfpessoa committed Aug 7, 2015
1 parent ebd4263 commit b8ce516
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 21 deletions.
49 changes: 49 additions & 0 deletions config.jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"disallowKeywords": [
"with"
],
"disallowKeywordsOnNewLine": [
"else"
],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleVarDecl": "exceptUndefined",
"disallowNewlineBeforeBlockStatements": true,
"disallowQuotedKeysInObjects": null,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpacesInFunction": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideParentheses": true,
"disallowTrailingWhitespace": true,
"maximumLineLength": 90,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireCapitalizedComments": true,
"requireCapitalizedConstructors": true,
"requireCurlyBraces": true,
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof"
],
"requireSpaceAfterLineComment": true,
"requireSpaceAfterBinaryOperators": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeObjectValues": true,
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
"requireTrailingComma": null,
"validateIndentation": 2,
"validateLineBreaks": "LF",
"validateQuoteMarks": "'"
}
12 changes: 5 additions & 7 deletions dist/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
-->

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

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

Expand All @@ -29,7 +27,7 @@

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

<div>
{{diff}}
<!--diff-->
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"main": "./src/main.js",

"dependencies": {
"yargs": "3.17.*",
"yargs": "3.18.*",
"extend": "3.0.0",
"diff2html": "*"
},
Expand Down
27 changes: 14 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* diff2html CLI (main.js)
* Diff to HTML CLI (main.js)
* Author: rtfpessoa
*
*/
Expand Down Expand Up @@ -66,11 +66,12 @@ var argv = require('yargs')
}
})
.example('diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1',
'diff last commit, line by line, word comparison between lines, previewed in the browser and input from git diff command')
'diff last commit, line by line, word comparison between lines,' +
'previewed in the browser and input from git diff command')
.example('diff2html -i file -- my-file-diff.diff', 'reading the input from a file')
.example('diff2html -f json -o stdout -- -M HEAD~1', 'print json format to stdout')
.example('diff2html -F my-pretty-diff.html -- -M HEAD~1', 'print to file')
.version(function () {
.version(function() {
return require('../package').version;
})
.help('h')
Expand All @@ -94,7 +95,7 @@ function main() {
print(content);
}
} else {
error("The input is empty. Try again.");
error('The input is empty. Try again.');
argv.help();
}

Expand All @@ -107,9 +108,9 @@ function getInput() {
} else {
var gitArgs;
if (argv._.length && argv._[0]) {
gitArgs = argv._.join(" ");
gitArgs = argv._.join(' ');
} else {
gitArgs = "-M HEAD~1"
gitArgs = '-M HEAD~1'
}

var diffCommand = 'git diff ' + gitArgs;
Expand Down Expand Up @@ -139,17 +140,17 @@ function getOutput(input) {
}

function preview(content) {
var filePath = "/tmp/diff." + argv.format;
var filePath = '/tmp/diff.' + argv.format;
writeFile(filePath, content);
runCmd("open " + filePath);
runCmd('open ' + filePath);
}

function prepareHTML(content) {
var template = readFile(__dirname + "/../dist/template.html", "utf8");
var css = readFile(__dirname + "/../dist/diff2html.css", "utf8");
var template = readFile(__dirname + '/../dist/template.html', 'utf8');
var css = readFile(__dirname + '/../dist/diff2html.css', 'utf8');
return template
.replace("{{css}}", css)
.replace("{{diff}}", content);
.replace('<!--css-->', '<style>\n' + css + '\n</style>')
.replace('<!--diff-->', content);
}

function prepareJSON(content) {
Expand All @@ -166,7 +167,7 @@ function error(msg) {

function readFile(filePath) {
var fs = require('fs');
return fs.readFileSync(filePath, "utf8");
return fs.readFileSync(filePath, 'utf8');
}

function writeFile(filePath, content) {
Expand Down

0 comments on commit b8ce516

Please sign in to comment.