Skip to content
Snippets Groups Projects
Commit cde46509 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

💄 Eslint

parent 6a065a16
No related branches found
No related tags found
No related merge requests found
Showing with 526 additions and 399 deletions
**/node_modules/*
{
"env": {
"commonjs": true,
"node": true
},
"plugins": [
"node"
],
"extends": "eslint:recommended",
"rules": {
"no-console": "off",
"indent": "off",
"comma-dangle": "off",
"quotes": "off",
"eqeqeq": [
"warn",
"allow-null"
],
"strict": [
"error",
"safe"
],
"no-unused-vars": [
"warn"
],
"no-extra-boolean-cast": [
"warn"
],
"complexity": [
"error",
{
"max": 12
}
],
"max-statements-per-line": [
"error",
{
"max": 3
}
],
"no-debugger": "error",
"no-dupe-keys": "error",
"no-unsafe-finally": "error",
"no-with": "error",
"no-useless-call": "error",
"no-spaced-func": "error",
"max-statements": [
"warn",
30
],
"max-depth": [
"error",
4
],
"no-throw-literal": [
"error"
],
"no-sequences": "error",
"no-warning-comments": [
"warn",
{
"terms": [
"fixme",
"xxx"
],
"location": "anywhere"
}
],
"radix": "error",
"yoda": "error",
"no-nested-ternary": "warn",
"no-whitespace-before-property": "error",
"no-trailing-spaces": [
"error",
{
"skipBlankLines": true
}
],
"space-in-parens": [
"warn",
"never"
],
"max-nested-callbacks": [
"error",
6
],
"eol-last": "warn",
"no-mixed-spaces-and-tabs": "error",
"no-negated-condition": "warn",
"no-unneeded-ternary": "error",
"no-multi-spaces": [
"warn",
{
"exceptions": {
"Property": true
}
}
],
"key-spacing": [
"warn",
{
"singleLine": {
"beforeColon": false,
"afterColon": true
},
"multiLine": {
"beforeColon": false,
"afterColon": true,
"mode": "minimum"
}
}
],
"node/no-missing-require": "error",
"node/no-unsupported-features": [ "error", { "version": 0.10 } ]
}
}
Loading
Loading
@@ -3,3 +3,4 @@ sentinel.dev.conf
npm-debug.log
node_modules
*.sw*
.eslintcache
{
"trailing": false,
"unused": true,
"node": true
}
module.exports = require('./lib/env');
\ No newline at end of file
'use strict';
module.exports = require('./lib/env');
/*jshint globalstrict:true, trailing:false, unused:true, node:true */
"use strict";
 
function configureNodeEnv() {
var nodeEnv = process.env.NODE_ENV;
if (nodeEnv) return nodeEnv;
/* Default to NODE_ENV=dev */
process.env.NODE_ENV = 'dev';
return 'dev';
}
/* Factory */
exports.create = function(configDirectory) {
var nconf = require('nconf');
Loading
Loading
@@ -11,14 +19,7 @@ exports.create = function(configDirectory) {
var SYSTEM_CONFIG_DIR = '/etc/gitter/';
 
/* Load configuration parameters */
var nodeEnv = process.env.NODE_ENV;
if(!nodeEnv) {
if(!nodeEnv) {
nodeEnv = 'dev';
}
process.env.NODE_ENV = nodeEnv;
}
var nodeEnv = configureNodeEnv();
 
var staging = process.env.STAGING;
staging = staging === '1' || staging === 'true';
Loading
Loading
@@ -35,24 +36,24 @@ exports.create = function(configDirectory) {
nconf.argv()
.env();
 
nconf.add('envUser', { type: 'file', file: path.join(configDir, 'config.' + nodeEnv + '.user-overrides.json') });
nconf.add('envUser', { type: 'file', file: path.join(configDir, 'config.' + nodeEnv + '.user-overrides.json') });
 
nconf.add('user', { type: 'file', file: path.join(configDir, 'config.user-overrides.json') });
nconf.add('user', { type: 'file', file: path.join(configDir, 'config.user-overrides.json') });
 
if(staging) {
nconf.add('systemStagingOverrides', { type: 'file', file: path.join(SYSTEM_CONFIG_DIR, 'config.' + nodeEnv + '-staging.overrides.json') });
nconf.add('systemStagingOverrides', { type: 'file', file: path.join(SYSTEM_CONFIG_DIR, 'config.' + nodeEnv + '-staging.overrides.json') });
}
 
nconf.add('systemOverrides', { type: 'file', file: path.join(SYSTEM_CONFIG_DIR, 'config.' + nodeEnv + '.overrides.json') });
nconf.add('systemOverrides', { type: 'file', file: path.join(SYSTEM_CONFIG_DIR, 'config.' + nodeEnv + '.overrides.json') });
 
if(staging) {
nconf.add('nodeEnvStaging', { type: 'file', file: path.join(configDir, 'config.' + nodeEnv + '-staging.json') });
nconf.add('nodeEnvStaging', { type: 'file', file: path.join(configDir, 'config.' + nodeEnv + '-staging.json') });
}
 
nconf.add('nodeEnv', { type: 'file', file: path.join(configDir, 'config.' + nodeEnv + '.json') });
nconf.add('systemDefaults', { type: 'file', file: path.join(SYSTEM_CONFIG_DIR, 'config.' + nodeEnv + '.json') });
nconf.add('nodeEnv', { type: 'file', file: path.join(configDir, 'config.' + nodeEnv + '.json') });
nconf.add('systemDefaults', { type: 'file', file: path.join(SYSTEM_CONFIG_DIR, 'config.' + nodeEnv + '.json') });
 
nconf.add('defaults', { type: 'file', file: path.join(configDir, 'config.default.json') });
nconf.add('defaults', { type: 'file', file: path.join(configDir, 'config.default.json') });
 
process.on('SIGHUP', function() {
async.parallel(
Loading
Loading
Loading
Loading
@@ -136,7 +136,7 @@ exports.create = function(configDirectory) {
mongo: {
/* Bring your own mongoose connection configurer */
configureMongoose: function(mongoose) {
return require('./mongoose-connection-configurer')({ config: config, logger: logger, mongoose: mongoose, env: env });
return require('./mongoose-connection-configurer')({ config: config, logger: logger, mongoose: mongoose, env: env });
}
},
 
Loading
Loading
'use strict';
 
var util = require('util');
var os = require('os');
var os = require('os');
var path = require('path');
var processName = require('./process-name')
 
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ exports.create = function(options) {
var transformMeta = require('./transform-meta');
 
var nconf = options.config;
if(!nconf) throw "options must contain config";
if(!nconf) throw new Error("options must contain config");
 
var defaultLogger = new winston.Logger({
transports: []
Loading
Loading
@@ -31,7 +31,7 @@ exports.create = function(options) {
}
 
fs.stat(fullname, function (err, stat) {
if (err && err.code == 'ENOENT') {
if (err && err.code === 'ENOENT') {
console.log('Log file no longer exists. Reopening');
return reopen();
}
Loading
Loading
@@ -39,7 +39,7 @@ exports.create = function(options) {
if(fileTransport._stream && fileTransport._stream.fd) {
 
fs.fstat(fileTransport._stream.fd, function(err2, fstat) {
if(stat.dev != fstat.dev || stat.ino !== fstat.ino) {
if(stat.dev !== fstat.dev || stat.ino !== fstat.ino) {
console.log('File inode mismatch. Reopening');
return reopen();
}
Loading
Loading
@@ -170,7 +170,7 @@ exports.create = function(options) {
var logLevel = nconf.get("logging:level");
 
nconf.events.on('reload', function() {
if(logLevel === nconf.get("logging:level")) {
if(logLevel === nconf.get("logging:level")) {
return;
}
 
Loading
Loading
Loading
Loading
@@ -23,21 +23,6 @@ function getPathTag(req) {
return path;
}
 
function getUserId(req) {
var user = req.user;
if (!user) return;
return user.id || user._id; // Learn objects or not
}
function getClientId(req) {
var authInfo = req.authInfo;
if (!authInfo) return;
var client = authInfo.client;
if (!client) return;
return client.id || client._id;
}
exports.create = function(options) {
var config = options.config;
 
Loading
Loading
@@ -48,22 +33,12 @@ exports.create = function(options) {
 
return responseTime(function (req, res, time) {
var routeTag = getPathTag(req);
// var userId = getUserId(req);
// var clientId = getClientId(req);
 
var tags = ['method:' + req.method, 'sc:' + res.statusCode];
if (routeTag) {
tags.push('route:' + routeTag);
}
 
// if (userId) {
// tags.push('user:' + userId);
// }
// if (clientId) {
// tags.push('client:' + clientId);
// }
debug("%s %s [%s] completed %s with in %sms", req.method, req.originalUrl, req.routeIdentifier, res.statusCode, time);
 
statsdClient.histogram('http.request', time, tags);
Loading
Loading
"use strict";
 
module.exports = function errorHandlerMiddleware(err, req, res, next) { // jshint unused:false
module.exports = function errorHandlerMiddleware(err, req, res, next) { // eslint-disable-line no-unused-vars
var message = res.locals.errorMessage || "Internal Server Error";
// TODO: Add an HTML version for HTML clients
res.send({ error: message, uniqueId: res.locals.errorIdentifer });
};
Loading
Loading
@@ -100,7 +100,7 @@ exports.create = function(options) {
errorIdentifer = Date.now();
 
// Send to sentry
errorReporter (err, {
errorReporter(err, {
type: 'response',
status: status,
userId: userId,
Loading
Loading
'use strict';
 
var mongodbConnString = require('mongodb-connection-string');
var mongodbArbiterDiscover = require('mongodb-arbiter-discovery');
var mongoDogStats = require('mongodb-datadog-stats');
var shutdown = require('shutdown');
var mongodbConnString = require('mongodb-connection-string');
var mongodbArbiterDiscover = require('mongodb-arbiter-discovery');
var mongoDogStats = require('mongodb-datadog-stats');
var shutdown = require('shutdown');
 
var MONGO_CONNECTION_OPTIONS = {
server: {
Loading
Loading
This diff is collapsed.
Loading
Loading
@@ -19,7 +19,7 @@ function transformMeta(meta, depth) {
 
var valType = typeof value;
 
if(valType == 'string' || valType === 'number' || valType === 'boolean') {
if(valType === 'string' || valType === 'number' || valType === 'boolean') {
return value;
}
 
Loading
Loading
@@ -27,7 +27,7 @@ function transformMeta(meta, depth) {
if(!value) return null;
 
/* Deal with mongo objectIds so we dont get binary logged */
if(valType == 'object' && value._bsontype === 'ObjectID') {
if(valType === 'object' && value._bsontype === 'ObjectID') {
return "" + value;
}
 
Loading
Loading
@@ -52,4 +52,4 @@ function transformMeta(meta, depth) {
return result;
}
 
module.exports = transformMeta;
\ No newline at end of file
module.exports = transformMeta;
Loading
Loading
@@ -25,6 +25,7 @@ exports.create = function(options) {
try {
console.log('The error handler crashed too');
} catch(e) {
/* */
}
}
 
Loading
Loading
Loading
Loading
@@ -48,6 +48,9 @@
"winston-udp": "^0.0.6"
},
"devDependencies": {
"eslint": "^2.11.1",
"eslint-plugin-mocha": "^3.0.0",
"eslint-plugin-node": "^1.4.0",
"mocha": "^1.18.2",
"retire": "^0.2.1",
"temp": "^0.8.3"
Loading
Loading
{
"env": {
"commonjs": true,
"node": true,
"mocha": true
},
"plugins": [
"mocha"
],
"rules": {
"mocha/no-exclusive-tests": "error",
"strict": [
"warn",
"safe"
],
"max-nested-callbacks": [
"error",
10
]
}
}
{
"undef": true,
"node": true,
"unused": true,
"predef": [
"describe",
"it",
"before",
"after",
"beforeEach",
"afterEach"
]
}
/*jslint node: true */
/*global describe:true, it: true, before:false, after:false */
"use strict";
 
var assert = require('assert');
Loading
Loading
@@ -25,4 +23,4 @@ describe('gitter-config', function() {
 
assert.equal('something', config.get('test:another_value'));
});
});
\ No newline at end of file
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment