Skip to content

Commit beddf38

Browse files
sonicoder86ngabor84
andcommitted
fix(lint): add linting
EME-5173 Co-authored-by: Gabor Nemeth <[email protected]>
1 parent dd45f37 commit beddf38

File tree

10 files changed

+49
-31
lines changed

10 files changed

+49
-31
lines changed

.eslintrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"mocha": true,
5+
"es6": true
6+
},
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": {
9+
"ecmaFeatures": {
10+
"impliedStrict": true
11+
}
12+
},
13+
"globals": {
14+
"expect": true
15+
},
16+
"rules": {
17+
"security/detect-object-injection": 0,
18+
"security/detect-non-literal-regexp": 0,
19+
"no-unused-expressions": 0,
20+
"func-style": 0
21+
},
22+
"extends": [
23+
"emarsys"
24+
]
25+
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"description": "Tiny and fast json logger with namespace support",
55
"main": "dist/index.js",
66
"scripts": {
7-
"test": "mocha --require ts-node/register ./src/ --recursive",
8-
"test:watch": "mocha --require ts-node/register ./src/ --recursive --watch",
7+
"test": "mocha --require ts-node/register ./src --recursive",
8+
"test:watch": "mocha --require ts-node/register ./src --recursive --watch",
9+
"lint": "eslint ./src/**/*.{ts,js}",
910
"build": "rm -rf dist && tsc --project ./tsconfig.json",
1011
"semantic-release": "CI=true semantic-release",
1112
"example-js": "DEBUG=* node examples/index-js.js",
@@ -33,7 +34,12 @@
3334
"devDependencies": {
3435
"@emartech/cls-adapter": "1.3.0",
3536
"@types/node": "18.7.2",
37+
"@typescript-eslint/parser": "5.35.1",
3638
"chai": "4.3.6",
39+
"eslint": "7.21.0",
40+
"eslint-config-emarsys": "5.1.0",
41+
"eslint-plugin-no-only-tests": "2.4.0",
42+
"eslint-plugin-security": "1.4.0",
3743
"express": "4.18.1",
3844
"koa": "2.13.4",
3945
"mocha": "10.0.0",

src/enabled/enabled.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { isNamespaceEnabled } = require('./enabled');
42

53
describe('isNamespaceAvailable', function() {

src/formatter/debug.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
2-
31
const { debugFormatter } = require('./debug');
42
const { ColorName } = require('../output/color-name/color-name');
53

64
describe('debug formatter', function() {
7-
afterEach(function () {
5+
afterEach(function() {
86
ColorName.reset();
97
});
108

src/formatter/json.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { jsonFormatter } = require('./json');
42

53
describe('json formatter', function() {

src/formatter/logentries.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { logentriesFormatter } = require('./logentries');
42

53
describe('logentries formatter', function() {

src/formatter/logentries.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
2-
31
const isNumeric = (value: unknown) => !isNaN(parseFloat(value as string)) && isFinite(value as number);
42

53
const isString = (value: unknown) => typeof value === 'string' || value instanceof String;
64

75
const convertToTag = (value: unknown, key: string) => {
86
if (isString(value)) {
97
value = JSON.stringify(value);
10-
} else if(isNumeric(value)) {
8+
} else if (isNumeric(value)) {
119
value = (value as number).toString();
1210
} else {
1311
value = '"' + JSON.stringify(value) + '"';

src/logger/logger.spec.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
'use strict';
2-
31
const { Logger } = require('./logger');
42
const { jsonFormatter } = require('../formatter/json');
53
const { consoleOutput } = require('../output/console');
64

75
describe('Logger', function() {
86
let logger;
9-
let outputStub;
107

118
beforeEach(function() {
129
logger = new Logger('mongo', true);
13-
outputStub = this.sandbox.stub(Logger.config, 'output');
10+
this.sandbox.stub(Logger.config, 'output');
1411
});
1512

1613
afterEach(function() {
@@ -214,20 +211,20 @@ describe('Logger', function() {
214211
expect(logArguments.error_data.length).to.eql(3004);
215212
});
216213

217-
describe('when not an Error instance is passed as error', function () {
214+
describe('when not an Error instance is passed as error', function() {
218215
[
219216
{ type: 'custom object', value: {} },
220217
{ type: 'string', value: 'error' },
221218
{ type: 'null', value: null },
222219
{ type: 'number', value: 12 },
223220
{ type: 'bool', value: true }
224221
].forEach(({ type, value }) => {
225-
it(`should not throw error when ${type} is passed as error`, function () {
222+
it(`should not throw error when ${type} is passed as error`, function() {
226223
expect(() => logger.customError('error', 'hi', value, { details: 'here' })).to.not.throw();
227224
});
228225
});
229226

230-
it('should log error properties from custom error object', function () {
227+
it('should log error properties from custom error object', function() {
231228
const errorObject = { name: 'Error', message: 'My custom error', stack: 'Stack', data: { value: 1 } };
232229

233230
logger.customError('error', 'hi', errorObject, { details: 'here' });
@@ -240,7 +237,7 @@ describe('Logger', function() {
240237
expect(logArguments.error_data).to.eql(JSON.stringify(errorObject.data));
241238
});
242239

243-
it('should not log additional or missing error properties from custom error object', function () {
240+
it('should not log additional or missing error properties from custom error object', function() {
244241
const errorObject = { color: 'color', value: 'value' };
245242

246243
logger.customError('error', 'hi', errorObject, { details: 'here' });

src/logger/logger.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ export class Logger {
130130
return;
131131
}
132132

133-
return stack.length > STACK_TRACE_LIMIT
134-
? stack.substring(0, STACK_TRACE_LIMIT) + ' ...'
135-
: stack;
133+
return stack.length > STACK_TRACE_LIMIT ?
134+
stack.substring(0, STACK_TRACE_LIMIT) + ' ...' :
135+
stack;
136136
}
137137

138138
_shortenData(data: unknown) {
@@ -142,9 +142,9 @@ export class Logger {
142142

143143
const stringifiedData: string = typeof data === 'object' ? JSON.stringify(data) : data as string;
144144

145-
return stringifiedData.length > DATA_LIMIT
146-
? stringifiedData.substring(0, DATA_LIMIT) + ' ...'
147-
: stringifiedData;
145+
return stringifiedData.length > DATA_LIMIT ?
146+
stringifiedData.substring(0, DATA_LIMIT) + ' ...' :
147+
stringifiedData;
148148
}
149149

150150
_getErrorDetails(error: Error) {
@@ -163,7 +163,9 @@ export class Logger {
163163
}
164164

165165
_getAxiosErrorDetails(error: AxiosError) {
166-
if (!error.isAxiosError) return {};
166+
if (!error.isAxiosError) {
167+
return {};
168+
}
167169

168170
return {
169171
request_method: error.config.method,

src/timer/timer.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { Logger } = require('../logger/logger');
42
const { Timer } = require('./timer');
53

0 commit comments

Comments
 (0)