Skip to content

Commit

Permalink
chore(lint): added linting to test files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Jones committed Nov 13, 2017
1 parent b65871a commit 906a774
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 323 deletions.
8 changes: 3 additions & 5 deletions lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const debug = require('debug')('log4js:configuration');

let cluster;
try {
cluster = require('cluster'); // eslint-disable-line global-require
cluster = require('cluster'); // eslint-disable-line global-require
} catch (e) {
debug('Clustering support disabled because require(cluster) threw an error: ', e);
}
Expand Down Expand Up @@ -36,14 +36,12 @@ function anInteger(thing) {
}

class Configuration {

throwExceptionIf(checks, message) {
const tests = Array.isArray(checks) ? checks : [checks];
tests.forEach((test) => {
if (test) {
throw new Error(
`Problem with log4js configuration: (${util.inspect(this.candidate, { depth: 5 })}) - ${message}`
);
throw new Error(`Problem with log4js configuration: (${util.inspect(this.candidate, { depth: 5 })})` +
` - ${message}`);
}
});
}
Expand Down
16 changes: 8 additions & 8 deletions lib/connect-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getUrl(req) {
}


/**
/**
* Adds custom {token, replacement} objects to defaults,
* overwriting the defaults if any tokens clash
*
Expand All @@ -37,8 +37,8 @@ function assembleTokens(req, res, customTokens) {
const a = array.concat();
for (let i = 0; i < a.length; ++i) {
for (let j = i + 1; j < a.length; ++j) {
// not === because token can be regexp object
/* eslint eqeqeq:0 */
// not === because token can be regexp object
/* eslint eqeqeq:0 */
if (a[i].token == a[j].token) {
a.splice(j--, 1);
}
Expand Down Expand Up @@ -91,15 +91,15 @@ function assembleTokens(req, res, customTokens) {
token: /:res\[([^\]]+)]/g,
replacement: function (_, field) {
return res._headers ?
(res._headers[field.toLowerCase()] || res.__headers[field])
: (res.__headers && res.__headers[field]);
(res._headers[field.toLowerCase()] || res.__headers[field])
: (res.__headers && res.__headers[field]);
}
});

return arrayUniqueTokens(customTokens.concat(defaultTokens));
}

/**
/**
* Return formatted log line.
*
* @param {String} str
Expand All @@ -114,7 +114,7 @@ function format(str, tokens) {
return str;
}

/**
/**
* Return RegExp Object about nolog
*
* @param {String|Array} nolog
Expand Down Expand Up @@ -154,7 +154,7 @@ function createNoLogCondition(nolog) {
}

if (Array.isArray(nolog)) {
// convert to strings
// convert to strings
const regexpsAsStrings = nolog.map(reg => (reg.source ? reg.source : reg));
regexp = new RegExp(regexpsAsStrings.join('|'));
}
Expand Down
16 changes: 8 additions & 8 deletions lib/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ function timestampLevelAndCategory(loggingEvent, colour, timezoneOffset) {
*/
function basicLayout(loggingEvent, timezoneOffset) {
return timestampLevelAndCategory(
loggingEvent,
undefined,
timezoneOffset
) + formatLogData(loggingEvent.data);
loggingEvent,
undefined,
timezoneOffset
) + formatLogData(loggingEvent.data);
}

/**
Expand All @@ -124,10 +124,10 @@ function basicLayout(loggingEvent, timezoneOffset) {
*/
function colouredLayout(loggingEvent, timezoneOffset) {
return timestampLevelAndCategory(
loggingEvent,
loggingEvent.level.colour,
timezoneOffset
) + formatLogData(loggingEvent.data);
loggingEvent,
loggingEvent.level.colour,
timezoneOffset
) + formatLogData(loggingEvent.data);
}

function messagePassThroughLayout(loggingEvent) {
Expand Down
1 change: 0 additions & 1 deletion lib/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ module.exports = function (customLevels) {
}
return this.level === otherLevel.level;
}

}

const defaultLevels = {
Expand Down
29 changes: 13 additions & 16 deletions lib/log4js.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const layouts = require('./layouts');

let cluster;
try {
cluster = require('cluster'); // eslint-disable-line global-require
cluster = require('cluster'); // eslint-disable-line global-require
} catch (e) {
debug('Clustering support disabled because require(cluster) threw an error: ', e);
}
Expand Down Expand Up @@ -78,9 +78,8 @@ function setLevelForCategory(category, level) {
debug(`setLevelForCategory: found ${categoryConfig} for ${category}`);
if (!categoryConfig) {
const sourceCategoryConfig = configForCategory(category);
debug(
`setLevelForCategory: no config found for category, found ${sourceCategoryConfig} for parents of ${category}`
);
debug('setLevelForCategory: no config found for category, found ' +
`${sourceCategoryConfig} for parents of ${category}`);
categoryConfig = { appenders: sourceCategoryConfig.appenders };
}
categoryConfig.level = level;
Expand Down Expand Up @@ -207,21 +206,19 @@ function configure(configurationFileOrObject) {

if (config.disableClustering) {
debug('Not listening for cluster messages, because clustering disabled.');
} else {
} else if (isPM2Master()) {
// PM2 cluster support
// PM2 runs everything as workers - install pm2-intercom for this to work.
// we only want one of the app instances to write logs
if (isPM2Master()) {
debug('listening for PM2 broadcast messages');
process.removeListener('message', receiver);
process.on('message', receiver);
} else if (cluster.isMaster) {
debug('listening for cluster messages');
cluster.removeListener('message', receiver);
cluster.on('message', receiver);
} else {
debug('not listening for messages, because we are not a master process');
}
debug('listening for PM2 broadcast messages');
process.removeListener('message', receiver);
process.on('message', receiver);
} else if (cluster.isMaster) {
debug('listening for cluster messages');
cluster.removeListener('message', receiver);
cluster.on('message', receiver);
} else {
debug('not listening for messages, because we are not a master process');
}

enabled = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const debug = require('debug')('log4js:logger');

let cluster;
try {
cluster = require('cluster'); // eslint-disable-line global-require
cluster = require('cluster'); // eslint-disable-line global-require
} catch (e) {
debug('Clustering support disabled because require(cluster) threw an error: ', e);
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
},
"scripts": {
"clean": "find test -type f ! -name '*.json' ! -name '*.js' ! -name '.eslintrc' -delete && rm *.log",
"lint": "eslint lib/ test/",
"prepush": "npm test",
"commitmsg": "validate-commit-msg",
"posttest": "npm run clean",
"pretest": "eslint lib/**/*",
"pretest": "eslint 'lib/**/*.js' 'test/**/*.js'",
"test": "tap 'test/tap/**/*.js'",
"coverage": "tap 'test/tap/**/*.js' --cov",
"codecov": "tap 'test/tap/**/*.js' --cov --coverage-report=lcov && codecov"
Expand Down

0 comments on commit 906a774

Please sign in to comment.