E5FF Merge pull request #618 from log4js-node/linting · wxqGitHub/log4js-node@1350753 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1350753

Browse files
authored
Merge pull request log4js-node#618 from log4js-node/linting
Linting
2 parents 7e008b9 + f093279 commit 1350753

16 files changed

+244
-288
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ coverage/
2121
.nyc_output/
2222
_site
2323
Gemfile.lock
24+
Dockerfile
25+
docker-compose.yml

.npmignore

Lines changed: 2 additions & 0 deletions
< F438 /tr>
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ Makefile
1414
coverage
1515
Gemfile
1616
Gemfile.lock
17+
docker-compose.yml
18+
Dockerfile

lib/configuration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class Configuration {
4040
const tests = Array.isArray(checks) ? checks : [checks];
4141
tests.forEach((test) => {
4242
if (test) {
43-
throw new Error(`Problem with log4js configuration: (${util.inspect(this.candidate, { depth: 5 })}) - ${message}`);
43+
throw new Error(`Problem with log4js configuration: (${util.inspect(this.candidate, { depth: 5 })})` +
44+
` - ${message}`);
4445
}
4546
});
4647
}

lib/connect-logger.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getUrl(req) {
2222
}
2323

2424

25-
/**
25+
/**
2626
* Adds custom {token, replacement} objects to defaults,
2727
* overwriting the defaults if any tokens clash
2828
*
@@ -37,8 +37,8 @@ function assembleTokens(req, res, customTokens) {
3737
const a = array.concat();
3838
for (let i = 0; i < a.length; ++i) {
3939
for (let j = i + 1; j < a.length; ++j) {
40-
// not === because token can be regexp object
41-
/* eslint eqeqeq:0 */
40+
// not === because token can be regexp object
41+
/* eslint eqeqeq:0 */
4242
if (a[i].token == a[j].token) {
4343
a.splice(j--, 1);
4444
}
@@ -91,15 +91,15 @@ function assembleTokens(req, res, customTokens) {
9191
token: /:res\[([^\]]+)]/g,
9292
replacement: function (_, field) {
9393
return res._headers ?
94-
(res._headers[field.toLowerCase()] || res.__headers[field])
95-
: (res.__headers && res.__headers[field]);
94+
(res._headers[field.toLowerCase()] || res.__headers[field])
95+
: (res.__headers && res.__headers[field]);
9696
}
9797
});
9898

9999
return arrayUniqueTokens(customTokens.concat(defaultTokens));
100100
}
101101

102-
/**
102+
/**
103103
* Return formatted log line.
104104
*
105105
* @param {String} str
@@ -114,7 +114,7 @@ function format(str, tokens) {
114114
return str;
115115
}
116116

117-
/**
117+
/**
118118
* Return RegExp Object about nolog
119119
*
120120
* @param {String|Array} nolog
@@ -154,7 +154,7 @@ function createNoLogCondition(nolog) {
154154
}
155155

156156
if (Array.isArray(nolog)) {
157-
// convert to strings
157+
// convert to strings
158158
const regexpsAsStrings = nolog.map(reg => (reg.source ? reg.source : reg));
159159
regexp = new RegExp(regexpsAsStrings.join('|'));
160160
}

lib/layouts.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ function timestampLevelAndCategory(loggingEvent, colour, timezoneOffset) {
112112
*/
113113
function basicLayout(loggingEvent, timezoneOffset) {
114114
return timestampLevelAndCategory(
115-
loggingEvent,
116-
undefined,
117-
timezoneOffset
118-
) + formatLogData(loggingEvent.data);
115+
loggingEvent,
116+
undefined,
117+
timezoneOffset
118+
) + formatLogData(loggingEvent.data);
119119
}
120120

121121
/**
@@ -124,10 +124,10 @@ function basicLayout(loggingEvent, timezoneOffset) {
124124
*/
125125
function colouredLayout(loggingEvent, timezoneOffset) {
126126
return timestampLevelAndCategory(
127-
loggingEvent,
128-
loggingEvent.level.colour,
129-
timezoneOffset
130-
) + formatLogData(loggingEvent.data);
127+
loggingEvent,
128+
loggingEvent.level.colour,
129+
timezoneOffset
130+
) + formatLogData(loggingEvent.data);
131131
}
132132

133133
function messagePassThroughLayout(loggingEvent) {

lib/levels.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module.exports = function (customLevels) {
3636
}
3737
return this.level === otherLevel.level;
3838
}
39-
4039
}
4140

4241
const defaultLevels = {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
},
2626
"scripts": {
2727
"clean": "find test -type f ! -name '*.json' ! -name '*.js' ! -name '.eslintrc' -delete && rm *.log",
28-
"lint": "eslint lib/ test/",
2928
"prepush": "npm test",
3029
"commitmsg": "validate-commit-msg",
3130
"posttest": "npm run clean",
32-
"pretest": "eslint lib/**/*",
31+
"pretest": "eslint 'lib/**/*.js' 'test/**/*.js'",
3332
"test": "tap 'test/tap/**/*.js'",
3433
"coverage": "tap 'test/tap/**/*.js' --cov",
3534
"codecov": "tap 'test/tap/**/*.js' --cov --coverage-report=lcov && codecov"
< B41A h3 id="heading-:R4dlab:" class="DiffFileHeader-module__file-name--mY1O5">test/tap/configuration-validation-test.js
Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ function testAppender(label) {
2424
test('log4js configuration validation', (batch) => {
2525
batch.test('should give error if config is just plain silly', (t) => {
2626
[null, undefined, '', ' ', []].forEach((config) => {
27-
const expectedError = new Error(
28-
`Problem with log4js configuration: (${util.inspect(config)}) - must be an object.`
29-
);
27+
const expectedError =
28+
new Error(`Problem with log4js configuration: (${util.inspect(config)}) - must be an object.`);
3029
t.throws(
3130
() => new Configuration(config),
3231
expectedError
@@ -37,34 +36,32 @@ test('log4js configuration validation', (batch) => {
3736
});
3837

3938
batch.test('should give error if config is an empty object', (t) => {
40-
const expectedError = new Error(
41-
'Problem with log4js configuration: ({}) - must have a property "appenders" of type object.'
42-
);
39+
const expectedError =
40+
new Error('Problem with log4js configuration: ({}) - must have a property "appenders" of type object.');
4341
t.throws(() => new Configuration({}), expectedError);
4442
t.end();
4543
});
4644

4745
batch.test('should give error if config has no appenders', (t) => {
48-
const expectedError = new Error< F438 /span>(
49-
'Problem with log4js configuration: ({ categories: {} }) - must have a property "appenders" of type object.'
50-
);
46+
const expectedError =
47+
new Error('Problem with log4js configuration: ({ categories: {} }) ' +
48+
'- must have a property "appenders" of type object.');
5149
t.throws(() => new Configuration({ categories: {} }), expectedError);
5250
t.end();
5351
});
5452

5553
batch.test('should give error if config has no categories', (t) => {
56-
const expectedError = new Error(
57-
'Problem with log4js configuration: ({ appenders: {} }) - must have a property "categories" of type object.'
58-
);
54+
const expectedError =
55+
new Error('Problem with log4js configuration: ({ appenders: {} }) ' +
56+
'- must have a property "categories" of type object.');
5957
t.throws(() => new Configuration({ appenders: {} }), expectedError);
6058
t.end();
6159
});
6260

6361
batch.test('should give error if appenders is not an object', (t) => {
64-
const error = new Error(
65-
'Problem with log4js configuration: ({ appenders: [], categories: [] })' +
66-
' - must have a property "appenders" of type object.'
67-
);
62+
const error =
63+
new Error('Problem with log4js configuration: ({ appenders: [], categories: [] })' +
64+
' - must have a property "appenders" of type object.');
6865
t.throws(
6966
() => new Configuration({ appenders: [], categories: [] }),
7067
error
@@ -73,10 +70,9 @@ test('log4js configuration validation', (batch) => {
7370
});
7471

7572
batch.test('should give error if appenders are not all valid', (t) => {
76-
const error = new Error(
77-
'Problem with log4js configuration: ({ appenders: { thing: \'cheese\' }, categories: {} })' +
78-
' - appender "thing" is not valid (must be an object with property "type")'
79-
);
73+
const error =
74+
new Error('Problem with log4js configuration: ({ appenders: { thing: \'cheese\' }, categories: {} })' +
75+
' - appender "thing" is not valid (must be an object with property "type")');
8076
t.throws(
8177
() => new Configuration({ appenders: { thing: 'cheese' }, categories: {} }),
8278
error
@@ -85,10 +81,8 @@ test('log4js configuration validation', (batch) => {
8581
});
8682

8783
batch.test('should require at least one appender', (t) => {
88-
const error = new Error(
89-
'Problem with log4js configuration: ({ appenders: {}, categories: {} })' +
90-
' - must define at least one appender.'
91-
);
84+
const error = new Error('Problem with log4js configuration: ({ appenders: {}, categories: {} })' +
85+
' - must define at least one appender.');
9286
t.throws(
9387
() => new Configuration({ appenders: {}, categories: {} }),
9488
error
@@ -97,11 +91,9 @@ test('log4js configuration validation', (batch) => {
9791
});
9892

9993
batch.test('should give error if categories are not all valid', (t) => {
100-
const error = new Error(
101-
'Problem with log4js configuration: ' +
94+
const error = new Error('Problem with log4js configuration: ' +
10295
'({ appenders: { stdout: { type: \'stdout\' } },\n categories: { thing: \'cheese\' } })' +
103-
' - category "thing" is not valid (must be an object with properties "appenders" and "level")'
104-
);
96+
' - category "thing" is not valid (must be an object with properties "appenders" and "level")');
10597
t.throws(
10698
() => new Configuration({ appenders: { stdout: { type: 'stdout' } }, categories: { thing: 'cheese' } }),
10799
error
@@ -110,27 +102,24 @@ test('log4js configuration validation', (batch) => {
110102
});
111103

112104
batch.test('should give error if default category not defined', (t) => {
113-
const error = new Error(
114-
'Problem with log4js configuration: ' +
105+
const error = new Error('Problem with log4js configuration: ' +
115106
'({ appenders: { stdout: { type: \'stdout\' } },\n' +
116107
' categories: { thing: { appenders: [ \'stdout\' ], level: \'ERROR\' } } })' +
117-
' - must define a "default" category.'
118-
);
108+
' - must define a "default" category.');
119109
t.throws(
120110
() => new Configuration({
121111
appenders: { stdout: { type: 'stdout' } },
122-
categories: { thing: { appenders: ['stdout'], level: 'ERROR' } } }
123-
),
112+
categories: { thing: { appenders: ['stdout'], level: 'ERROR' } }
113+
}),
124114
error
125115
);
126116
t.end();
127117
});
128118

129119
batch.test('should require at least one category', (t) => {
130-
const error = new Error(
131-
'Problem with log4js configuration: ({ appenders: { stdout: { type: \'stdout\' } }, categories: {} })' +
132-
' - must define at least one category.'
133-
);
120+
const error =
121+
new Error('Problem with log4js configuration: ({ appenders: { stdout: { type: \'stdout\' } }, categories: {} })' +
122+
' - must define at least one category.');
134123
t.throws(
135124
() => new Configuration({ appenders: { stdout: { type: 'stdout' } }, categories: {} }),
136125
error
@@ -139,12 +128,10 @@ test('log4js configuration validation', (batch) => {
139128
});
140129

141130
batch.test('should give error if category.appenders is not an array', (t) => {
142-
const error = new Error(
143-
'Problem with log4js configuration: ' +
131+
const error = new Error('Problem with log4js configuration: ' +
144132
'({ appenders: { stdout: { type: \'stdout\' } },\n' +
145133
' categories: { thing: { appenders: {}, level: \'ERROR\' } } })' +
146-
' - category "thing" is not valid (appenders must be an array of appender names)'
147-
);
134+
' - category "thing" is not valid (appenders must be an array of appender names)');
148135
t.throws(
149136
() => new Configuration({
150137
appenders: { stdout: { type: 'stdout' } },
@@ -156,12 +143,10 @@ test('log4js configuration validation', (batch) => {
156143
});
157144

158145
batch.test('should give error if category.appenders is empty', (t) => {
159-
const error = new Error(
160-
'Problem with log4js configuration: ' +
146+
const error = new Error('Problem with log4js configuration: ' +
161147
'({ appenders: { stdout: { type: \'stdout\' } },\n' +
162148
' categories: { thing: { appenders: [], level: \'ERROR\' } } })' +
163-
' - category "thing" is not valid (appenders must contain at least one appender name)'
164-
);
149+
' - category "thing" is not valid (appenders must contain at least one appender name)');
165150
t.throws(
166151
() => new Configuration({
167152
appenders: { stdout: { type: 'stdout' } },
@@ -173,12 +158,10 @@ test('log4js configuration validation', (batch) => {
173158
});
174159

175160
batch.test('should give error if categories do not refer to valid appenders', (t) => {
176-
const error = new Error(
177-
'Problem with log4js configuration: ' +
161+
const error = new Error('Problem with log4js configuration: ' +
178162
'({ appenders: { stdout: { type: \'stdout\' } },\n' +
179163
' categories: { thing: { appenders: [ \'cheese\' ], level: \'ERROR\' } } })' +
180-
' - category "thing" is not valid (appender "cheese" is not defined)'
181-
);
164+
' - category "thing" is not valid (appender "cheese" is not defined)');
182165
t.throws(
183166
() => new Configuration({
184167
appenders: { stdout: { type: 'stdout' } },
@@ -190,13 +173,11 @@ test('log4js configuration validation', (batch) => {
190173
});
191174

192175
batch.test('should give error if category level is not valid', (t) => {
193-
const error = new Error(
194-
'Problem with log4js configuration: ' +
176+
const error = new Error('Problem with log4js configuration: ' +
195177
'({ appenders: { stdout: { type: \'stdout\' } },\n' +
196178
' categories: { default: { appenders: [ \'stdout\' ], level: \'Biscuits\' } } })' +
197179
' - category "default" is not valid (level "Biscuits" not recognised; ' +
198-
'valid levels are ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, MARK, OFF)'
199-
);
180+
'valid levels are ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, MARK, OFF)');
200181
t.throws(
201182
() => new Configuration({
202183
appenders: { stdout: { type: 'stdout' } },
@@ -208,12 +189,10 @@ test('log4js configuration validation', (batch) => {
208189
});
209190

210191
batch.test('should give error if appender type cannot be found', (t) => {
211-
const error = new Error(
212-
'Problem with log4js configuration: ' +
192+
const error = new Error('Problem with log4js configuration: ' +
213193
'({ appenders: { thing: { type: \'cheese\' } },\n' +
214194
' categories: { default: { appenders: [ \'thing\' ], level: \'ERROR\' } } })' +
215-
' - appender "thing" is not valid (type "cheese" could not be found)'
216-
);
195+
' - appender "thing" is not valid (type "cheese" could not be found)');
217196
t.throws(
218197
() => new Configuration({
219198
appenders: { thing: { type: 'cheese' } },
@@ -278,9 +257,7 @@ test('log4js configuration validation', (batch) => {
278257
sandboxConfig.requires[
279258
`${path.join(mainPath, '../../node_modules/tap/node_modules/nyc/bin/cheese')}`
280259
] = testAppender('correct');
281-
const SandboxedConfiguration = sandbox.require(
282-
'../../lib/configuration', sandboxConfig
283-
);
260+
const SandboxedConfiguration = sandbox.require('../../lib/configuration', sandboxConfig);
284261

285262
const config = new SandboxedConfiguration({
286263
appenders: { thing: { type: 'cheese' } },

test/tap/dateFileAppender-test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ test('../../lib/appenders/dateFile', (batch) => {
5555
logger.info('this should not be written to the file');
5656
logger.warn('this should be written to the file');
5757

58-
t.teardown(() => { removeFile('date-file-test.log'); });
59-
60-
fs.readFile(path.join(__dirname, 'date-file-test.log'), 'utf8', (err, contents) => {
61-
t.include(contents, `this should be written to the file${EOL}`);
62-
t.equal(contents.indexOf('this should not be written to the file'), -1);
63-
t.end();
58+
log4js.shutdown(() => {
59+
fs.readFile(path.join(__dirname, 'date-file-test.log'), 'utf8', (err, contents) => {
60+
t.include(contents, `this should be written to the file${EOL}`);
61+
t.equal(contents.indexOf('this should not be written to the file'), -1);
62+
t.end();
63+
});
6464
});
65+
66+
t.teardown(() => { removeFile('date-file-test.log'); });
6567
});
6668

6769
batch.test('configure with options.alwaysIncludePattern', (t) => {
@@ -96,13 +98,13 @@ test('../../lib/appenders/dateFile', (batch) => {
9698
t.teardown(() => { removeFile(`date-file-test${thisTime}`); });
9799

98100
// wait for filesystem to catch up
99-
setTimeout(() => {
101+
log4js.shutdown(() => {
100102
fs.readFile(path.join(__dirname, `date-file-test${thisTime}`), 'utf8', (err, contents) => {
101103
t.include(contents, 'this should be written to the file with the appended date');
102104
t.include(contents, 'this is existing data', 'should not overwrite the file on open (issue #132)');
103105
t.end();
104106
});
105-
}, 100);
107+
});
106108
});
107109

108110
batch.test('should flush logs on shutdown', (t) => {

test/tap/fileAppender-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ test('log4js fileAppender', (batch) => {
8888
type: 'file', filename: testFile, maxLogSize: 100, backups: 0
8989
}
9090
},
91-
categories: { default: { appenders: ['file'], level: 'debug' } }
91+
categories: {
92+
default: { appenders: ['file'], level: 'debug' }
93+
}
9294
});
9395

9496
logger.info('This is the first log message.');

0 commit comments

Comments
 (0)
0