Skip to content

Commit

Permalink
Merge pull request #65 from trojs/feature/update-20240725
Browse files Browse the repository at this point in the history
Update linting
  • Loading branch information
w3nl authored Jul 25, 2024
2 parents 3db45ce + a988f54 commit ff26d98
Show file tree
Hide file tree
Showing 23 changed files with 905 additions and 1,371 deletions.
22 changes: 20 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
},
"root": true,
"extends": [
"standard",
"@hckrnews/eslint-config",
"plugin:import/recommended",
"plugin:n/recommended",
"plugin:jsdoc/recommended",
"plugin:sonarjs/recommended"
"plugin:sonarjs/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"sourceType": "module",
Expand All @@ -33,6 +34,13 @@
"webextensions": true
},
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "always"
}
],
"block-scoped-var": "error",
"complexity": [
"error",
Expand All @@ -57,6 +65,12 @@
"warn",
20
],
"max-len": [
"warn",
{
"code": 120
}
],
"linebreak-style": [
"warn",
"unix"
Expand Down Expand Up @@ -168,6 +182,10 @@
"off",
{}
],
"n/no-unsupported-features/node-builtins": [
"off",
{}
],
"vars-on-top": "error",
"for-direction": "error",
"getter-return": [
Expand Down
1,065 changes: 249 additions & 816 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@trojs/logger",
"description": "Winston logger for TroJS",
"version": "0.4.2",
"version": "0.4.3",
"author": {
"name": "Pieter Wigboldus",
"url": "https://trojs.org/"
Expand Down Expand Up @@ -31,17 +31,22 @@
],
"main": "src/logger.js",
"devDependencies": {
"@trojs/error": "^3.0.0",
"@hckrnews/eslint-config": "^3.0.0",
"@trojs/error": "^3.0.0",
"c8": "^10.0.0",
"eslint": "^8.23.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^48.0.6",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-sonarjs": "^0.25.0",
"jscpd": "^4.0.0"
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-html": "^8.1.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.8.3",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.0.0",
"eslint-plugin-sonarjs": "^0.25.1",
"jscpd": "^4.0.0",
"prettier": "^3.3.3"
},
"repository": {
"type": "git",
Expand All @@ -57,12 +62,12 @@
"error"
],
"dependencies": {
"@trojs/enum": "^3.0.0",
"@trojs/mutator": "^0.4.0",
"@trojs/objects": "^8.0.0",
"@sentry/integrations": "^7.117.0",
"@sentry/node": "^7.117.0",
"@sentry/tracing": "^7.117.0",
"@trojs/enum": "^3.0.0",
"@trojs/mutator": "^0.4.0",
"@trojs/objects": "^8.0.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
Expand Down
110 changes: 56 additions & 54 deletions src/__tests__/logger.feature.test.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,61 @@
import test from 'node:test'
import assert from 'node:assert'
import makeLogger from '../logger.js'
import test from 'node:test';
import assert from 'node:assert';
import makeLogger from '../logger.js';

test('Test the make loggers', async (t) => {
await t.test('It should make the loggers', () => {
const logger = makeLogger({
loggers: [{
type: 'console'
}]
})
await t.test('It should make the loggers', () => {
const logger = makeLogger({
loggers: [
{
type: 'console',
},
],
});

assert.strictEqual(logger.level, 'info')
assert.deepEqual(logger.levels, {
fatal: 0,
error: 1,
warn: 2,
info: 3,
debug: 4,
trace: 5
})
assert.strictEqual(logger.silent, undefined)
assert.strictEqual(logger.writable, true)
assert.strictEqual(logger.readable, true)
assert.strictEqual(logger.allowHalfOpen, true)
assert.deepEqual(logger.defaultMeta, {})
assert.strictEqual(logger.exitOnError, true)
assert.deepEqual(logger.format, {
options: {}
})
assert.strictEqual(logger.filename, undefined)
assert.strictEqual(logger.options, undefined)
})
assert.strictEqual(logger.level, 'info');
assert.deepEqual(logger.levels, {
fatal: 0,
error: 1,
warn: 2,
info: 3,
debug: 4,
trace: 5,
});
assert.strictEqual(logger.silent, undefined);
assert.strictEqual(logger.writable, true);
assert.strictEqual(logger.readable, true);
assert.strictEqual(logger.allowHalfOpen, true);
assert.deepEqual(logger.defaultMeta, {});
assert.strictEqual(logger.exitOnError, true);
assert.deepEqual(logger.format, {
options: {},
});
assert.strictEqual(logger.filename, undefined);
assert.strictEqual(logger.options, undefined);
});

await t.test('It should work without loggers', () => {
const logger = makeLogger({})
await t.test('It should work without loggers', () => {
const logger = makeLogger({});

assert.strictEqual(logger.level, 'info')
assert.deepEqual(logger.levels, {
fatal: 0,
error: 1,
warn: 2,
info: 3,
debug: 4,
trace: 5
})
assert.strictEqual(logger.silent, undefined)
assert.strictEqual(logger.writable, true)
assert.strictEqual(logger.readable, true)
assert.strictEqual(logger.allowHalfOpen, true)
assert.deepEqual(logger.defaultMeta, {})
assert.strictEqual(logger.exitOnError, true)
assert.deepEqual(logger.format, {
options: {}
})
assert.strictEqual(logger.filename, undefined)
assert.strictEqual(logger.options, undefined)
})
})
assert.strictEqual(logger.level, 'info');
assert.deepEqual(logger.levels, {
fatal: 0,
error: 1,
warn: 2,
info: 3,
debug: 4,
trace: 5,
});
assert.strictEqual(logger.silent, undefined);
assert.strictEqual(logger.writable, true);
assert.strictEqual(logger.readable, true);
assert.strictEqual(logger.allowHalfOpen, true);
assert.deepEqual(logger.defaultMeta, {});
assert.strictEqual(logger.exitOnError, true);
assert.deepEqual(logger.format, {
options: {},
});
assert.strictEqual(logger.filename, undefined);
assert.strictEqual(logger.options, undefined);
});
});
56 changes: 28 additions & 28 deletions src/helpers/__tests__/stackdriver.unit.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import test from 'node:test'
import assert from 'node:assert'
import stackdriver from '../stackdriver.js'
import test from 'node:test';
import assert from 'node:assert';
import stackdriver from '../stackdriver.js';

test('Test the stackdriver helper', async (t) => {
await t.test('It should generate the meta data object', () => {
const meta = stackdriver({ level: 'error', defaultLevel: 'info' })
const result = meta({
message: 'test'
})
await t.test('It should generate the meta data object', () => {
const meta = stackdriver({ level: 'error', defaultLevel: 'info' });
const result = meta({
message: 'test',
});

assert.strictEqual(result.level, 50)
assert.strictEqual(result.severity, 'ERROR')
assert.strictEqual(result.message, 'test')
assert.strictEqual(result.time.constructor.name, 'Number')
assert.strictEqual(result.pid.constructor.name, 'Number')
assert.strictEqual(result.hostname.constructor.name, 'String')
})
assert.strictEqual(result.level, 50);
assert.strictEqual(result.severity, 'ERROR');
assert.strictEqual(result.message, 'test');
assert.strictEqual(result.time.constructor.name, 'Number');
assert.strictEqual(result.pid.constructor.name, 'Number');
assert.strictEqual(result.hostname.constructor.name, 'String');
});

await t.test('It should generate the meta data object', () => {
const meta = stackdriver({ level: 'something', defaultLevel: 'info' })
const result = meta({
message: 'test2'
})
await t.test('It should generate the meta data object', () => {
const meta = stackdriver({ level: 'something', defaultLevel: 'info' });
const result = meta({
message: 'test2',
});

assert.strictEqual(result.level, 30)
assert.strictEqual(result.severity, 'INFO')
assert.strictEqual(result.message, 'test2')
assert.strictEqual(result.time.constructor.name, 'Number')
assert.strictEqual(result.pid.constructor.name, 'Number')
assert.strictEqual(result.hostname.constructor.name, 'String')
})
})
assert.strictEqual(result.level, 30);
assert.strictEqual(result.severity, 'INFO');
assert.strictEqual(result.message, 'test2');
assert.strictEqual(result.time.constructor.name, 'Number');
assert.strictEqual(result.pid.constructor.name, 'Number');
assert.strictEqual(result.hostname.constructor.name, 'String');
});
});
50 changes: 26 additions & 24 deletions src/helpers/stackdriver.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import os from 'node:os'
import os from 'node:os';

const levelToSeverity = {
trace: 'DEBUG',
debug: 'DEBUG',
info: 'INFO',
warn: 'WARNING',
error: 'ERROR',
fatal: 'CRITICAL'
}
trace: 'DEBUG',
debug: 'DEBUG',
info: 'INFO',
warn: 'WARNING',
error: 'ERROR',
fatal: 'CRITICAL',
};

const levels = {
trace: 10,
debug: 20,
info: 30,
warn: 40,
error: 50,
fatal: 60
}
trace: 10,
debug: 20,
info: 30,
warn: 40,
error: 50,
fatal: 60,
};

const stackdriver = ({ level, defaultLevel }) => (info) => ({
...info,
severity: levelToSeverity[level] || levelToSeverity[defaultLevel],
level: levels[level] || levels[defaultLevel],
time: Date.now(),
pid: process.pid,
hostname: os.hostname()
})
const stackdriver =
({ level, defaultLevel }) =>
(info) => ({
...info,
severity: levelToSeverity[level] || levelToSeverity[defaultLevel],
level: levels[level] || levels[defaultLevel],
time: Date.now(),
pid: process.pid,
hostname: os.hostname(),
});

export default stackdriver
export default stackdriver;
Loading

0 comments on commit ff26d98

Please sign in to comment.