Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit c9cae94

Browse files
Mark MoffatMark Moffat
Mark Moffat
authored and
Mark Moffat
committed
Update and lint the bajeebers out of the project
1 parent 225365d commit c9cae94

11 files changed

+2307
-920
lines changed

.eslintignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
./locales/*.js
1+
./locales/*.js
2+
/public/javascripts/**/*.js
3+
/locales/**/*.js
4+
/public/stylesheets/**/*.css

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "standard",
33
"plugins": [
44
"standard",
5-
"promise"
5+
"promise",
6+
"extra-rules"
67
],
78
"parserOptions": {
89
"ecmaVersion": 2017
@@ -26,6 +27,7 @@
2627
"space-unary-ops" : 2,
2728
"no-undef": 1,
2829
"no-unused-vars": 1,
30+
"extra-rules/no-commented-out-code": "warn",
2931
"keyword-spacing": [
3032
"error", {
3133
"before": false, "after": false, "overrides": {

app.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ handlebars = handlebars.create({
7171
app_context = '/' + app_context;
7272
}
7373
if(keywords){
74-
let array = keywords.split(','); let links = '';
74+
const array = keywords.split(','); let links = '';
7575
for(let i = 0; i < array.length; i++){
7676
if(array[i].trim() !== ''){
7777
links += '<a href="' + app_context + '/search/' + array[i].trim() + '">' + array[i].trim() + '</a> <span class="keywordSeporator">|</span> ';
@@ -270,7 +270,7 @@ if(app_context !== ''){
270270

271271
// catch 404 and forward to error handler
272272
app.use((req, res, next) => {
273-
let err = new Error('Not Found');
273+
const err = new Error('Not Found');
274274
err.status = 404;
275275
next(err);
276276
});
@@ -357,32 +357,32 @@ if(config.settings.database.type === 'embedded'){
357357
});
358358
}
359359

360-
function exitHandler(options, err) {
361-
if (options.cleanup) {
360+
function exitHandler(options, err){
361+
if(options.cleanup){
362362
console.log('clean');
363363
if(config.settings.database.type !== 'embedded'){
364364
app.db.close();
365365
}
366366
}
367-
if (err) {
367+
if(err){
368368
console.log(err.stack);
369369
}
370-
if (options.exit) {
370+
if(options.exit){
371371
process.exit();
372372
}
373373
}
374374

375-
//do something when app is closing
376-
process.on('exit', exitHandler.bind(null,{cleanup:true}));
375+
// do something when app is closing
376+
process.on('exit', exitHandler.bind(null, { cleanup: true }));
377377

378-
//catches ctrl+c event
379-
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
378+
// catches ctrl+c event
379+
process.on('SIGINT', exitHandler.bind(null, { exit: true }));
380380

381381
// catches "kill pid" (for example: nodemon restart)
382-
process.on('SIGUSR1', exitHandler.bind(null, {exit:true}));
383-
process.on('SIGUSR2', exitHandler.bind(null, {exit:true}));
382+
process.on('SIGUSR1', exitHandler.bind(null, { exit: true }));
383+
process.on('SIGUSR2', exitHandler.bind(null, { exit: true }));
384384

385-
//catches uncaught exceptions
386-
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
385+
// catches uncaught exceptions
386+
process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
387387

388388
module.exports = app;

bin/uglify.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var uglifycss = require('uglifycss');
2-
var uglifyjs = require('uglify-js');
3-
var path = require('path');
4-
var fs = require('fs');
1+
const uglifycss = require('uglifycss');
2+
const uglifyjs = require('uglify-js');
3+
const path = require('path');
4+
const fs = require('fs');
55

66
// css files
77
uglifyFile('public/stylesheets/style.css', 'css');
@@ -21,14 +21,14 @@ uglifyFile('public/javascripts/codemirror.inline-attachment.js', 'js');
2121

2222
function uglifyFile(filename, type){
2323
if(type === 'css'){
24-
var cssfileContents = fs.readFileSync(filename, 'utf8');
25-
var cssUglified = uglifycss.processString(cssfileContents);
26-
var cssMiniFilename = filename.substring(0, filename.length - 4) + '.min.' + type;
24+
const cssfileContents = fs.readFileSync(filename, 'utf8');
25+
const cssUglified = uglifycss.processString(cssfileContents);
26+
const cssMiniFilename = filename.substring(0, filename.length - 4) + '.min.' + type;
2727
fs.writeFileSync(cssMiniFilename, cssUglified, 'utf8');
2828
}
2929
if(type === 'js'){
30-
var rawCode = fs.readFileSync(filename, 'utf8');
31-
var jsUglified = uglifyjs.minify(rawCode, {
30+
const rawCode = fs.readFileSync(filename, 'utf8');
31+
const jsUglified = uglifyjs.minify(rawCode, {
3232
compress: {
3333
dead_code: true,
3434
global_defs: {
@@ -37,7 +37,7 @@ function uglifyFile(filename, type){
3737
}
3838
});
3939

40-
var jsMiniFilename = filename.substring(0, filename.length - 3) + '.min.' + type;
40+
const jsMiniFilename = filename.substring(0, filename.length - 3) + '.min.' + type;
4141
fs.writeFileSync(jsMiniFilename, jsUglified.code, 'utf8');
4242
}
4343
}

data/mongodbUpgrade.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// There are no duplication checks in place. Please only run this script once.
99
// ** IMPORTANT **
1010

11-
var Nedb = require('nedb');
12-
var mongodb = require('mongodb');
13-
var async = require('async');
14-
var path = require('path');
15-
var common = require('../routes/common');
16-
var config = common.read_config();
17-
var ndb;
11+
const Nedb = require('nedb');
12+
const mongodb = require('mongodb');
13+
const async = require('async');
14+
const path = require('path');
15+
const common = require('../routes/common');
16+
const config = common.read_config();
17+
let ndb;
1818

1919
// check for DB config
2020
if(!config.settings.database.connection_string){
@@ -23,18 +23,18 @@ if(!config.settings.database.connection_string){
2323
}
2424

2525
// Connect to the MongoDB database
26-
mongodb.connect(config.settings.database.connection_string, {}, function(err, mdb){
26+
mongodb.connect(config.settings.database.connection_string, {}, (err, mdb) => {
2727
if(err){
28-
console.log("Couldn't connect to the Mongo database");
28+
console.log('Couldn\'t connect to the Mongo database');
2929
console.log(err);
3030
process.exit(1);
3131
}
3232

3333
console.log('Connected to: ' + config.settings.database.connection_string);
3434
console.log('');
3535

36-
insertKB(mdb, function(KBerr, report){
37-
insertUsers(mdb, function(Usererr, report){
36+
insertKB(mdb, (KBerr, report) => {
37+
insertUsers(mdb, (Usererr, report) => {
3838
if(KBerr || Usererr){
3939
console.log('There was an error upgrading to MongoDB. Check the console output');
4040
}else{
@@ -46,17 +46,17 @@ mongodb.connect(config.settings.database.connection_string, {}, function(err, md
4646
});
4747

4848
function insertKB(db, callback){
49-
var collection = db.collection('kb');
49+
const collection = db.collection('kb');
5050
console.log(path.join(__dirname, 'kb.db'));
5151
ndb = new Nedb(path.join(__dirname, 'kb.db'));
52-
ndb.loadDatabase(function (err){
52+
ndb.loadDatabase((err) => {
5353
if(err){
5454
console.error('Error while loading the data from the NeDB database');
5555
console.error(err);
5656
process.exit(1);
5757
}
5858

59-
ndb.find({}, function (err, docs){
59+
ndb.find({}, (err, docs) => {
6060
if(docs.length === 0){
6161
console.error('The NeDB database contains no data, no work required');
6262
console.error('You should probably check the NeDB datafile path though!');
@@ -66,7 +66,7 @@ function insertKB(db, callback){
6666
}
6767

6868
console.log('Inserting articles into MongoDB...');
69-
async.each(docs, function (doc, cb){
69+
async.each(docs, (doc, cb) => {
7070
console.log('Article inserted: ' + doc.kb_title);
7171

7272
// check for permalink. If it is not set we set the old NeDB _id to the permalink to stop links from breaking.
@@ -77,8 +77,8 @@ function insertKB(db, callback){
7777
// delete the old ID and let MongoDB generate new ones
7878
delete doc._id;
7979

80-
collection.insert(doc, function (err){ return cb(err); });
81-
}, function (err){
80+
collection.insert(doc, (err) => { return cb(err); });
81+
}, (err) => {
8282
if(err){
8383
console.log('An error happened while inserting data');
8484
callback(err, null);
@@ -93,16 +93,16 @@ function insertKB(db, callback){
9393
};
9494

9595
function insertUsers(db, callback){
96-
var collection = db.collection('users');
96+
const collection = db.collection('users');
9797
ndb = new Nedb(path.join(__dirname, 'users.db'));
98-
ndb.loadDatabase(function (err){
98+
ndb.loadDatabase((err) => {
9999
if(err){
100100
console.error('Error while loading the data from the NeDB database');
101101
console.error(err);
102102
process.exit(1);
103103
}
104104

105-
ndb.find({}, function (err, docs){
105+
ndb.find({}, (err, docs) => {
106106
if(docs.length === 0){
107107
console.error('The NeDB database contains no data, no work required');
108108
console.error('You should probably check the NeDB datafile path though!');
@@ -112,14 +112,14 @@ function insertUsers(db, callback){
112112
}
113113

114114
console.log('Inserting users into MongoDB...');
115-
async.each(docs, function (doc, cb){
115+
async.each(docs, (doc, cb) => {
116116
console.log('User inserted: ' + doc.user_email);
117117

118118
// delete the old ID and let MongoDB generate new ones
119119
delete doc._id;
120120

121-
collection.insert(doc, function (err){ return cb(err); });
122-
}, function (err){
121+
collection.insert(doc, (err) => { return cb(err); });
122+
}, (err) => {
123123
if(err){
124124
console.error('An error happened while inserting user data');
125125
callback(err, null);
@@ -132,5 +132,3 @@ function insertUsers(db, callback){
132132
});
133133
});
134134
};
135-
136-

locales/en.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,8 @@
180180
"dsdsds is not defined": "dsdsds is not defined",
181181
"dfdfd": "dfdfd",
182182
"url.URL.parse is not a function": "url.URL.parse is not a function",
183-
"A user with that email does not exist.": "A user with that email does not exist."
183+
"A user with that email does not exist.": "A user with that email does not exist.",
184+
"Visible state": "Visible state",
185+
"Public": "Public",
186+
"Private": "Private"
184187
}

0 commit comments

Comments
 (0)