Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
theneubeck committed Feb 20, 2019
1 parent 35aa296 commit 2c22b24
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 46 deletions.
17 changes: 6 additions & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"extends": ["eslint:recommended"],
"plugins": ["json", "prettier"],
"rules": {
"prettier/prettier": "error",
"arrow-parens": 2,
"arrow-spacing": 2,
"brace-style": [2, "1tbs", {"allowSingleLine": false}],
Expand All @@ -21,7 +23,6 @@
"handle-callback-err": 2,
"key-spacing": [1, {"beforeColon": false, "afterColon": true}],
"keyword-spacing": 1,
"indent": [1, 2, {"SwitchCase": 1, "MemberExpression": 1}],
"new-cap": 2,
"new-parens": 1,
"no-alert": 2,
Expand Down Expand Up @@ -65,24 +66,18 @@
"no-use-before-define": [2, "nofunc"],
"no-var": 2,
"no-with": 2,
"object-curly-spacing": ["error", "never"],
"object-curly-spacing": 0,
"prefer-arrow-callback": 2,
"prefer-const": ["error", {"destructuring": "all"}],
"prefer-template": 1,
"quotes": [1, "double", {"avoidEscape": true}],
"semi": [2, "always"],
"semi-spacing": [1, {"before": false, "after": true}],
"space-before-blocks": 1,
"space-before-function-paren": [1, {"anonymous": "always", "named": "never"}],
"space-before-function-paren": [1, {"anonymous": "never", "named": "never"}],
"space-infix-ops": 1,
"space-unary-ops": [1, {"words": true, "nonwords": false}],
"space-in-parens": ["error", "never"],
"strict": [2, "global"],
"template-curly-spacing": ["error", "never"],
"yoda": [1, "never"],
"require-await": ["error"],
"no-restricted-modules": ["warn", {
"patterns": ["test-data/*"]
}]
"yoda": [1, "never"]
}
}
44 changes: 27 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function logFilename() {
return path.join(process.cwd(), "logs", `${appConfig.envName}.log`);
}


function truncateTooLong(info) {
if (Buffer.byteLength(info.message, "utf8") > 60 * 1024) {
info.message = "too big to log";
Expand All @@ -53,12 +52,15 @@ function metaDataFormat(info) {

function defaultFormatter() {
return format.printf((info) => {
const meta = Object.keys(info).reduce((acc, key) => {
if (!["message", "metaData", "level"].includes(key)) {
acc[key] = info[key];
}
return acc;
}, {...info.metaData});
const meta = Object.keys(info).reduce(
(acc, key) => {
if (!["message", "metaData", "level"].includes(key)) {
acc[key] = info[key];
}
return acc;
},
{...info.metaData}
);

return `${info.timestamp} - ${info.level}: ${info.message}\t${stringify(meta)}`;
});
Expand All @@ -69,25 +71,33 @@ const transports = [new PromTransport()];
const formatter = config.logJson ? format.json() : defaultFormatter();

if (config.log === "file") {
transports.push(new winston.transports.File({
filename: logFilename()
}));
transports.push(
new winston.transports.File({
filename: logFilename()
})
);
}

if (config.log === "stdout") {
transports.push(new winston.transports.Console());
}

if (config.sysLogOpts) {
transports.push(new winston.transports.Syslog(Object.assign({
type: "RFC5424",
localhost: process.env.HOSTNAME,
app_name: callingAppName, // eslint-disable-line camelcase
eol: "\n"
}, config.sysLogOpts)));
transports.push(
new winston.transports.Syslog(
Object.assign(
{
type: "RFC5424",
localhost: process.env.HOSTNAME,
app_name: callingAppName, // eslint-disable-line camelcase
eol: "\n"
},
config.sysLogOpts
)
)
);
}


const logger = winston.createLogger({
level: config.logLevel || "info",
levels: logLevels.levels,
Expand Down
4 changes: 2 additions & 2 deletions lib/get-loc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function getLoc(depth) {
let stack, file, frame;

const pst = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, innerStack) {
Error.prepareStackTrace = function(_, innerStack) {
Error.prepareStackTrace = pst;
return innerStack;
};
Expand All @@ -18,7 +18,7 @@ function getLoc(depth) {
do {
frame = stack.shift();
file = frame && frame.getFileName();
} while (stack.length && file === "module.js" || file.includes("node_modules"));
} while ((stack.length && file === "module.js") || file.includes("node_modules"));

let calleePath;
if (process.cwd()) {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"version": "2.1.4",
"scripts": {
"test": "mocha --exit && eslint . --cache && depcheck --ignores=\"prettier\"",
"test": "mocha --exit && eslint . --cache && depcheck",
"posttest": "eslint --cache .",
"lint": "eslint --cache .",
"format": "prettier **/*.js --write && eslint . --fix"
Expand All @@ -34,8 +34,10 @@
"chai": "^3.5.0",
"depcheck": "^0.6.11",
"eslint": "^4.19.1",
"eslint-plugin-json": "^1.4.0",
"eslint-plugin-prettier": "^3.0.1",
"mocha": "^5.2.0",
"mocha-cakes-2": "^2.0.1",
"prettier": "^1.15.3"
"prettier": "^1.16.4"
}
}
17 changes: 8 additions & 9 deletions test/feature/logging-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Feature("Logging", () => {
Scenario("Logging debug with JSON format", () => {
const message = "Message";
const data = {
"meta": {
"createdAt": "2017-09-24-00:00T00:00:00.000Z",
"updatedAt": "2017-09-24-00:00T00:00:00.000Z",
"correlationId": "sample-correlation-id"
meta: {
createdAt: "2017-09-24-00:00T00:00:00.000Z",
updatedAt: "2017-09-24-00:00T00:00:00.000Z",
correlationId: "sample-correlation-id"
}
};

Expand All @@ -32,14 +32,13 @@ Feature("Logging", () => {
});
});


Scenario("Logging a too big message JSON format", () => {
const message = "Message".repeat(9000);
const data = {
"meta": {
"createdAt": "2017-09-24-00:00T00:00:00.000Z",
"updatedAt": "2017-09-24-00:00T00:00:00.000Z",
"correlationId": "sample-correlation-id"
meta: {
createdAt: "2017-09-24-00:00T00:00:00.000Z",
updatedAt: "2017-09-24-00:00T00:00:00.000Z",
correlationId: "sample-correlation-id"
}
};

Expand Down
1 change: 0 additions & 1 deletion test/meta-data-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const {logger: winston} = require("../");
const transport = require("./helpers/test-transport");


describe("logging messages with default metaData", () => {
const data = {
meta: {
Expand Down
64 changes: 60 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,20 @@ [email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

eslint-plugin-json@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-json/-/eslint-plugin-json-1.4.0.tgz#4d29f3a4c08d412df739bd65049ce23636515af8"
integrity sha512-CECvgRAWtUzuepdlPWd+VA7fhyF9HT183pZnl8wQw5x699Mk/MbME/q8xtULBfooi3LUbj6fToieNmsvUcDxWA==
dependencies:
vscode-json-languageservice "^3.2.1"

eslint-plugin-prettier@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.1.tgz#19d521e3981f69dd6d14f64aec8c6a6ac6eb0b0d"
integrity sha512-/PMttrarPAY78PLvV3xfWibMOdMDl57hmlQ2XqFeA37wd+CJ7WSxV7txqjVPHi/AAFKd2lX0ZqfsOc/i5yFCSQ==
dependencies:
prettier-linter-helpers "^1.0.0"

eslint-scope@^3.7.1:
version "3.7.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.3.tgz#bb507200d3d17f60247636160b4826284b108535"
Expand Down Expand Up @@ -571,6 +585,11 @@ fast-deep-equal@^1.0.0:
version "1.1.0"
resolved "http://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"

fast-diff@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==

fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
Expand Down Expand Up @@ -863,6 +882,11 @@ json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"

jsonc-parser@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-2.0.3.tgz#6d4199ccab7f21ff5d2a4225050c54e981fb21a2"
integrity sha512-WJi9y9ABL01C8CxTKxRRQkkSpY/x2bo4Gy0WuiZGrInxQqgxQpvkBCLNcDYcHOSdhx4ODgbFcgAvfL49C+PHgQ==

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/kuler/-/kuler-1.0.1.tgz#ef7c784f36c9fb6e16dd3150d152677b2b0228a6"
Expand Down Expand Up @@ -1154,10 +1178,17 @@ prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"

prettier@^1.15.3:
version "1.15.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.3.tgz#1feaac5bdd181237b54dbe65d874e02a1472786a"
integrity sha512-gAU9AGAPMaKb3NNSUUuhhFAS7SCO4ALTN4nRIn6PJ075Qd28Yn2Ig2ahEJWdJwJmlEBTUfC7mMUSFy8MwsOCfg==
prettier-linter-helpers@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
dependencies:
fast-diff "^1.1.2"

prettier@^1.16.4:
version "1.16.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717"
integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==

process-nextick-args@~2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -1517,6 +1548,31 @@ validate-npm-package-license@^3.0.1:
spdx-correct "^3.0.0"
spdx-expression-parse "^3.0.0"

vscode-json-languageservice@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.2.1.tgz#991d51128ebd81c5525d0578cabfa5b03e3cba2a"
integrity sha512-ee9MJ70/xR55ywvm0bZsDLhA800HCRE27AYgMNTU14RSg20Y+ngHdQnUt6OmiTXrQDI/7sne6QUOtHIN0hPQYA==
dependencies:
jsonc-parser "^2.0.2"
vscode-languageserver-types "^3.13.0"
vscode-nls "^4.0.0"
vscode-uri "^1.0.6"

vscode-languageserver-types@^3.13.0:
version "3.14.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.14.0.tgz#d3b5952246d30e5241592b6dde8280e03942e743"
integrity sha512-lTmS6AlAlMHOvPQemVwo3CezxBp0sNB95KNPkqp3Nxd5VFEnuG1ByM0zlRWos0zjO3ZWtkvhal0COgiV1xIA4A==

vscode-nls@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.0.0.tgz#4001c8a6caba5cedb23a9c5ce1090395c0e44002"
integrity sha512-qCfdzcH+0LgQnBpZA53bA32kzp9rpq/f66Som577ObeuDlFIrtbEJ+A/+CCxjIh4G8dpJYNCKIsxpRAHIfsbNw==

vscode-uri@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.6.tgz#6b8f141b0bbc44ad7b07e94f82f168ac7608ad4d"
integrity sha512-sLI2L0uGov3wKVb9EB+vIQBl9tVP90nqRvxSoJ35vI3NjxE8jfsE5DSOhWgSunHSZmKS4OCi2jrtfxK7uyp2ww==

[email protected]:
version "0.0.11"
resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.0.11.tgz#a16d025eb931bd03b52f308caed0f40fcebe9532"
Expand Down

0 comments on commit 2c22b24

Please sign in to comment.