Skip to content

Commit

Permalink
Merge pull request #104 from ripper234/add-linter
Browse files Browse the repository at this point in the history
Add eslint
  • Loading branch information
natekonimbo authored Feb 16, 2017
2 parents addad9b + af87b8e commit 038b43b
Show file tree
Hide file tree
Showing 23 changed files with 705 additions and 503 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public/gentelella/**/*.js
*.min.js
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
"extends": "standard",
"plugins": [
"standard",
"promise"
],
"rules": {
// Used in tests
"no-undef": ["off"],

// Style
"semi": ["off"],
"indent": ["off"],
"eol-last": ["off"],
"quotes": ["off"],
"operator-linebreak": ["off"],
"space-before-function-paren": ["off"],
"spaced-comment": ["off"],
"brace-style": ["off"],
"padded-blocks": ["off"],
"camelcase": ["off"],
"space-infix-ops": ["off"],
"comma-spacing": ["off"],
"no-trailing-spaces": ["off"],
"key-spacing": ["off"],
"block-spacing": ["off"],
"space-unary-ops": ["off"],
"comma-dangle": ["off"],
"one-var": ["off"],
}
};
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Before contributing, please review this guide.

## <a name="question"></a> Got a Question or Problem?

* Join our Slack and ask us at #sparksystem channel
* [Join our Slack](https://www.hamsterpad.com/chat/midburnos) and ask us at #sparksystem channel
* Email: **[email protected]**

## <a name="issue"></a> Found an Issue?
Expand Down Expand Up @@ -65,7 +65,8 @@ Before you submit your pull request consider the following guidelines:
- Have you searched for existing, related issues and pull requests?
- Is this a new feature that can stand alone as an external component?
- Is the change being proposed clearly explained and motivated?

- Does `npm lint` pass? (We use eslint with [Standard.js](http://standardjs.com/) style)
- Does `npm test` pass?
See: [Branching, patching and merging documentation](/docs/development/branching.md) for more details.

That's it! Thank you for your contribution!
Expand Down
26 changes: 13 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ log.info('Spark is starting...');
var app = express();

// Middleware registration
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));

// Log every HTTP request
app.use(morganLogger('dev', {
stream: log.logger.stream({
level: 'info',
filter: function(message) {
filter: function (message) {
if ((typeof message === "undefined") || (message === null)) return true;
return !
(message.includes('/stylesheets/') || message.includes('/images/'));
Expand All @@ -49,7 +49,7 @@ app.use(compileSass({
}));
app.use(express.static(path.join(__dirname, 'public')));

app.use(function(req, res, next) {
app.use(function (req, res, next) {
res.locals.req = req;
res.locals.path = req.path.split('/');
next();
Expand Down Expand Up @@ -112,8 +112,8 @@ i18next
//cookieExpirationDate: new Date(),
//cookieDomain: 'SparkMidburn'
}
}, function() {
middleware.addRoute(i18next, '/:lng', ['en', 'he'], app, 'get', function(req, res) {
}, function () {
middleware.addRoute(i18next, '/:lng', ['en', 'he'], app, 'get', function (req, res) {
//endpoint function
log.info("ROUTE");
});
Expand Down Expand Up @@ -165,7 +165,7 @@ log.info('Spark environment: NODE_ENV =', process.env.NODE_ENV, ', app.env =', a
// ==============

// Catch 404 and forward to error handler
app.use(function(req, res, next) {
app.use(function (req, res, next) {
var err = new Error('Not Found: ' + req.url);
err.status = 404;
next(err);
Expand All @@ -174,9 +174,9 @@ app.use(function(req, res, next) {
// Development error handler - will print stacktrace
if (app.get('env') === 'development') {

app.use(function(err, req, res, next) {
app.use(function (err, req, res, next) {
// Handle CSRF token errors
if (err.code == 'EBADCSRFTOKEN') {
if (err.code === 'EBADCSRFTOKEN') {
res.status(403);
res.render('pages/error', {
errorMessage: 'Illegal action. Your connection details has been logged.',
Expand All @@ -195,9 +195,9 @@ if (app.get('env') === 'development') {
}
// Production error handler - no stacktraces leaked to user
else {
app.use(function(err, req, res, next) {
app.use(function (err, req, res, next) {
// Handle CSRF token errors
if (err.code == 'EBADCSRFTOKEN') {
if (err.code === 'EBADCSRFTOKEN') {
res.status(403);
res.render('pages/error', {
errorMessage: 'Illegal action. Your connection details has been logged.',
Expand All @@ -214,11 +214,11 @@ else {
}

// Handler for unhandled rejections
process.on('unhandledRejection', function(reason, p) {
process.on('unhandledRejection', function (reason, p) {
log.error("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason);
});

process.on('warning', function(warning) {
process.on('warning', function (warning) {
log.warn(warning.name); // Print the warning name
log.warn(warning.message); // Print the warning message
log.warn(warning.stack); // Print the stack trace
Expand All @@ -230,4 +230,4 @@ app.use(fileUpload());
// == Export our app ==
module.exports = app;

log.info("--- Spark is running :) ---");
log.info("--- Spark is running :) ---");
4 changes: 2 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const opsworks = require('../opsworks.js');

module.exports = {
module.exports = {
database: opsworks.db,

server: opsworks.server,
Expand All @@ -24,4 +24,4 @@ module.exports = {
},

published_camps_origin: 'http://54.194.247.12'
};
};
64 changes: 31 additions & 33 deletions libs/logger.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,69 @@
const path = require('path');
const winston = require('winston');
const config = require('config');
const assert = require('assert');
const sprintf = require("sprintf-js").sprintf;
const dateFormat = require('dateformat');


module.exports = function(module) {
module.exports = function (module) {
assert(module);
assert(module.id);

var appDir = path.dirname(require.main.filename);
var id = path.relative(appDir, module.id);
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
timestamp: function() {
return dateFormat(Date.now(), "dd/mm/yy hh:MM:ss.l");
},
formatter: function(options) {
// Return string will be passed to logger.
return sprintf("%-33s", options.timestamp() +' '+ options.level.toUpperCase() +' '+ id + ' : ') + (options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' );
}
})
]

var logger = new(winston.Logger)({
transports: [
new(winston.transports.Console)({
timestamp: function () {
return dateFormat(Date.now(), "dd/mm/yy hh:MM:ss.l");
},
formatter: function (options) {
// Return string will be passed to logger.
return sprintf("%-33s", options.timestamp() + ' ' + options.level.toUpperCase() + ' ' + id + ' : ') + (options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '');
}
})
]
});

function log (level, msg, vars) {
logger.log(level, msg, vars);
function log(level, msg, vars) {
logger.log(level, msg, vars);
}

// Make Morgan log work with Winston
// http://stackoverflow.com/a/28824464/11236
logger.stream = function(params) {
logger.stream = function (params) {
return {
write: function(message, encoding){
write: function (message, encoding) {
if (params.filter && !params.filter(message)) {
return;
}

if (message.endsWith('\n')) {
message = message.slice(0, -1);
}
logger.log(params.level, message);
}
}
};

return {
log : log,
logger : logger,
log: log,

logger: logger,

// Aliases
debug : function (msg, vars) {
debug: function (msg, vars) {
log('debug', msg, vars);
},
info : function (msg, vars) {
info: function (msg, vars) {
log('info', msg, vars);
},
warn : function (msg, vars) {
warn: function (msg, vars) {
log('warn', msg, vars);
},
error : function (msg, vars) {
error: function (msg, vars) {
log('error', msg, vars);
},
};
}
}
Loading

0 comments on commit 038b43b

Please sign in to comment.