Commit 7db19364 authored by Isabella Skořepová's avatar Isabella Skořepová

Make jslint happy

parent a8218152
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : false, // true: Require {} for every new block or scope
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
"quotmark" : "single", // Quotation mark consistency
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : 5, // {int} Max number of formal params allowed per function
"maxdepth" : 5, // {int} Max depth of nested blocks (within functions)
"maxstatements" : 40, // {int} Max number statements per function
"maxcomplexity" : 10, // {int} Max cyclomatic complexity per function
"maxlen" : 120, // {int} Max number of characters per line
// Relaxing
"asi" : true, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"esversion" : 6, // {int} Specify the ECMAScript version to which the code must adhere.
"funcscope" : true, // true: Tolerate defining variables inside control statements
// Environments
"browser" : false, // Web Browser (window, document, etc)
"devel" : true, // Development/debugging (alert, confirm, etc)
"jquery" : false, // jQuery
"mocha" : true, // Mocha
"node" : true, // Node.js
// Custom Globals
"globals" : {} // additional predefined global variables
}
......@@ -34,23 +34,23 @@ var sitegin = function(config) {
var startTime = moment();
runAgain = false;
if(isRunning) {
console.log("Generator is still running. Queing another run after it finishes.")
console.log('Generator is still running. Queing another run after it finishes.')
runAgain = true;
return;
}
console.log("================================================================================")
console.log("Running generator")
console.log('================================================================================')
console.log('Running generator')
isRunning = true;
jobs.run('pipeline',jobs)
.then(function() {
isRunning = false;
console.log("Generator finished in",moment().diff(startTime,'seconds'),'seconds')
console.log('Generator finished in',moment().diff(startTime,'seconds'),'seconds')
doSync();
if(runAgain) run();
})
.catch(function(e) {
isRunning = false;
console.log("Generator crashed in",moment().diff(startTime,'seconds'),'seconds')
console.log('Generator crashed in',moment().diff(startTime,'seconds'),'seconds')
if(runAgain) run();
if(e.stack)
console.log(e.stack)
......@@ -89,7 +89,7 @@ var sitegin = function(config) {
// sitegin reload
jobs.onReload(function() {
console.log("Sitegin reloaded");
console.log('Sitegin reloaded');
run();
})
}
......@@ -106,19 +106,19 @@ var copyStaticFiles = function(builddir) {
fsextra.copy(
'static',
builddir,
function(file){ return !(file.match(".git") || file.match("static/articles")); },
function(){console.log("copy static done");}
function(file){ return !(file.match('.git') || file.match('static/articles')); },
function(){console.log('copy static done');}
);
fsextra.copy(
'static/articles',
builddir+"/clanek",
function(){console.log("copy static/articles done");}
builddir+'/clanek',
function(){console.log('copy static/articles done');}
);
fsextra.copy(
'theme/static',
builddir,
function(file){ return !file.match("\\.git") },
function(){console.log("copy theme/static done");}
function(file){ return !file.match('\\.git') },
function(){console.log('copy theme/static done');}
);
}
......@@ -127,10 +127,10 @@ var rendersass = function(builddir) {
var sass = require('node-sass');
var fs = require('fs');
sass.render ({file: "theme/sass/style.scss"},function(err, result) {
if(err == null) {
console.log("compiled sass");
fs.writeFile(builddir+"/theme/style.css",result.css);
} else console.log("error ", err);
sass.render ({file: 'theme/sass/style.scss'},function(err, result) {
if(err === null) {
console.log('compiled sass');
fs.writeFile(builddir+'/theme/style.css',result.css);
} else console.log('error ', err);
});
};
......@@ -13,9 +13,9 @@ var options = cli.parse({
});
module.exports = function() {
var builddir = "build";
if(!options.noserver) builddir = "build-debug";
var builddir = 'build';
if(!options.noserver) builddir = 'build-debug';
if(options.uiport == 'port+1') {
options.uiport = options.port+1;
}
......
......@@ -8,22 +8,22 @@ var git = require('nodegit-kit');
var path = require('path');
var moment = require('moment');
var pathToRepo = path.resolve("content");
var pathToRepo = path.resolve('content');
// Returns promise for patch of single commit
var gitShow = function(repo, commit_data) {
var gitShow = function(repo, commitData) {
var commit, tree, parentTree;
return nodegit.Revparse.single(repo, commit_data.commit)
return nodegit.Revparse.single(repo, commitData.commit)
.then((obj) => {
return nodegit.Commit.lookup(repo, obj.id());
})
.then((_commit) => {
commit = _commit;
if(commit.parentcount() < 1) return null;
return parent = commit.getParents(1);
return commit.getParents(1);
})
.then((parents) => {
if(parents == null) return null;
if(parents === null) return null;
return parents[0].getTree();
})
.then((_parentTree) => {
......@@ -40,7 +40,7 @@ var gitShow = function(repo, commit_data) {
.then((patches) => {
return [
patches,
commit_data
commitData
];
});
}
......@@ -90,10 +90,10 @@ module.exports = function(obj) {
var newestCommit = commits[0];
var oldestCommit = commits[commits.length-1];
if(article.metadata.date == undefined)
if(article.metadata.date === undefined)
article.metadata.date = {};
if(article.metadata.date.creation == undefined)
if(article.metadata.date.creation === undefined)
article.metadata.date.creation = oldestCommit.date;
article.metadata.date.modification = newestCommit.date;
......@@ -101,9 +101,9 @@ module.exports = function(obj) {
if(article.metadata.author === undefined)
article.metadata.author = {}
if(article.metadata.author.name == undefined)
if(article.metadata.author.name === undefined)
article.metadata.author.name = oldestCommit.author.name
if(article.metadata.author.email == undefined)
if(article.metadata.author.email === undefined)
article.metadata.author.email = oldestCommit.author.email
article.commits = commits;
......
'use strict';
var syntaxError = require('syntax-error');
var fs = require('fs');
var chokidar = require('chokidar');
var eventEmitter = new (require('events').EventEmitter);
var eventEmitter = new (require('events').EventEmitter)();
var jobList = {};
var watchers = [];
......@@ -16,15 +18,16 @@ function JobError(message, name) {
var onReload = function() {}
var requireError = function(e, jobName, module, reject) {
if(e instanceof SyntaxError) {
console.log(module+': '+e);
var resolved = require.resolve(module);
fs.readFile(resolved, 'utf8', function(err, content) {
console.log(syntaxError(content,resolved));
reject(new JobError('Failed to register job '+jobName,'Require'))
reject(new JobError('Failed to register job '+jobName+' (SyntaxError)','Require'))
})
} else {
if(e.code === 'MODULE_NOT_FOUND')
console.log(e.toString());
reject(new JobError('Failed to register job '+jobName,'Require'))
reject(new JobError('Failed to register job '+jobName+' ('+e+')','Require'))
}
}
......@@ -91,9 +94,10 @@ var jobs = {
registerMultiple: function() {
var regs = [];
var watch = true;
var i;
for(i in arguments) {
var job = arguments[i];
if(i == 0) {
if(i === '0') {
if(job.watch !== undefined) watch = job.watch;
} else {
regs.push(jobs.register(job[0], job[1], watch));
......@@ -109,14 +113,14 @@ var jobs = {
try {
return jobList[jobName].f.apply(null, Array.prototype.slice.call(arguments, 1));
} catch(e) {
console.log("Error running job",jobName);
console.log('Error running job',jobName);
console.log(jobList[jobName]);
throw e;
}
},
runSequence: function() {
var prom;
console.log("Running",Array.prototype.slice.call(arguments, 0))
console.log('Running',Array.prototype.slice.call(arguments, 0))
var jobSequence = [].splice.call(arguments, 0);
jobSequence.forEach(function(job){
if(prom === undefined) {
......
......@@ -13,15 +13,15 @@ var toURL = function(url) {
}
renderer.heading = function(text, level, raw) {
return '<h'
+ (level+2)
+ ' id="'
+ toURL(raw)
+ '">'
+ text
+ '</h'
+ (level+2)
+ '>\n';
return '<h' +
(level+2) +
' id="' +
toURL(raw) +
'">' +
text +
'</h' +
(level+2) +
'>\n';
}
renderer.paragraph = function(text) {
......@@ -43,8 +43,8 @@ marked.setOptions({
module.exports = function(obj) {
obj.pages.forEach(function(article) {
renderer.image = function(href, title, text) {
href = href.split(path.sep).join("/");
href = href.split(" =");
href = href.split(path.sep).join('/');
href = href.split(' =');
var size = href[1];
href = href[0];
var rel = path.relative(process.cwd(),path.resolve(article.filename,href));
......
'use strict';
/*
* This job renders `data` using nunjucks template `type`
*/
......@@ -26,7 +27,7 @@ env.addFilter('paginationList', function(page, count) {
}
curPage = page;
for(var i = 0; i < count; i++) {
for(let i = 0; i < count; i++) {
curPage = curPage.metadata.nextpage;
if(curPage === undefined) break;
pages.push(curPage);
......
......@@ -4,23 +4,23 @@ var path = require('path');
var jsesc = require('jsesc')
var readPageWorker = function(content, obj) {
if(content === undefined) throw new Error("content is undefined");
if(content === undefined) throw new Error('content is undefined');
var head = content.substring(0,4)
if(head !== '+++\n')
throw new Error('Failed to parse file '+obj.filename+':\n'+
'Wrong header (expected "+++\\n" got "'+jsesc(head)+'")')
content = content.substring(4);
var fm_end = content.indexOf("+++\n");
if(fm_end < 0) {
var fmEnd = content.indexOf('+++\n');
if(fmEnd < 0) {
console.log(jsesc(content));
throw new Error('Cannot find terminating +++\n in file '+obj.filename);
}
obj.content = content.substring(fm_end+4);
obj.content = content.substring(fmEnd+4);
try {
obj.metadata = toml.parse(content.substring(0,fm_end-1)+"\n");
obj.metadata = toml.parse(content.substring(0,fmEnd-1)+'\n');
} catch(e) {
console.log(obj.filename+": Failed to parse metadata");
console.log(obj.filename+': Failed to parse metadata');
throw e;
}
if(obj.metadata.date && obj.metadata.date.creation) obj.metadata.date.creation = moment(obj.metadata.date.creation);
......
'use strict';
var moment = require('moment');
var jobs = require('./jobs');
......@@ -7,7 +9,7 @@ var toURL = function(url) {
module.exports = function(obj) {
return new Promise(function(resolve, reject) {
var tags = new Array();
var tags = [];
var tagPages = {};
obj.pages.forEach(function(article) {
if(article.metadata.tags) {
......@@ -20,7 +22,7 @@ module.exports = function(obj) {
ntags.push(tag);
if(tags.map(function(e) { return e.url; }).indexOf(tag.url) < 0)
tags.push(tag)
if(tagPages[tag.url] == undefined) tagPages[tag.url] = new Array();
if(tagPages[tag.url] === undefined) tagPages[tag.url] = [];
tagPages[tag.url].push(article)
})
article.metadata.tags = ntags;
......@@ -31,11 +33,11 @@ module.exports = function(obj) {
obj.redirects = [];
var generateTagPages = function(file, pageList) {
var p = {};
p.type = "redirect";
p.file = file;
p.content = file+"/1";
obj.redirects.push(p);
var pg = {};
pg.type = 'redirect';
pg.file = file;
pg.content = file+'/1';
obj.redirects.push(pg);
pageList.sort(function (a, b) {
var rhs = a.metadata.date.creation;
......@@ -43,18 +45,18 @@ module.exports = function(obj) {
return lhs > rhs ? 1 : lhs < rhs ? -1 : 0;
})
var c = 0;
var p = 0;
let p = 0;
var tagPage;
var prevurl;
var prevpage;
var firstpage;
var lastpage;
tagPageList = [];
var tagPageList = [];
pageList.forEach(function(page) {
if(c == 0) {
if(c === 0) {
p++;
if(tagPage !== undefined) {
tagPage.metadata.nexturl = file+"/"+p;
tagPage.metadata.nexturl = file+'/'+p;
obj.tags.push(tagPage);
tagPageList.push(tagPage);
}
......@@ -62,15 +64,15 @@ module.exports = function(obj) {
if(firstpage === undefined) firstpage = tagPage;
lastpage = tagPage;
tagPage.file = file+"/"+p;
tagPage.type = "tag";
tagPage.file = file+'/'+p;
tagPage.type = 'tag';
tagPage.metadata.firstpage = firstpage;
tagPage.metadata.prevpage = prevpage;
tagPage.metadata.prevurl = prevurl;
tagPage.metadata.thispage = tagPage;
tagPage.metadata.pagenumber = p;
tagPage.content = new Array();
tagPage.content = [];
if(prevpage !== undefined)
prevpage.metadata.nextpage = tagPage;
prevurl = tagPage.file;
......@@ -89,7 +91,7 @@ module.exports = function(obj) {
}
tags.forEach(function(tag) {
generateTagPages("tag/"+tag.url, tagPages[tag.url])
generateTagPages('tag/'+tag.url, tagPages[tag.url])
})
resolve(obj);
})
......
This diff is collapsed.
......@@ -9,7 +9,7 @@ module.exports = function(obj) {
var todo = 0;
var writeFile = function(article) {
var filename = path.join(builddir,article.file,"index.html");
var filename = path.join(builddir,article.file,'index.html');
mkdirp(path.dirname(filename), function() {
fs.writeFile(filename, article.content, function(err) {
if(err) reject(err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment