Skip to content

Commit

Permalink
style: eslint & m. fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
amithm7 committed Dec 28, 2021
1 parent f1fdda2 commit 2a800fc
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.vscode
.prettierrc
.prettierignore
.eslintrc.cjs

node_modules/
worker/
Expand All @@ -16,3 +17,4 @@ log/
*.md
LICENSE
wrangler.toml
package-lock.json
39 changes: 39 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
env: {
// Which globals variables are allowed.
es2021: true,
node: true,
worker: true,
},

extends: [
// See: https://github.com/google/eslint-config-google
"google",
],

parserOptions: {
ecmaVersion: 13,
sourceType: "module",
},

plugins: ["prettier"],
rules: {
// Rules disabled to avoid conflicts with prettier
// See: https://github.com/prettier/eslint-config-prettier
"indent": 0,
"object-curly-spacing": 0,
"operator-linebreak": 0,
"space-before-function-paren": 0,

// Our rules overrides.
"comma-dangle": 0,
"require-jsdoc": 0,
"quotes": ["error", "double", { allowTemplateLiterals: true }],
"no-unused-vars": "warn",

// Enforces rules from .prettierrc file.
// These should be fixed automatically with formatting.
// See: https://github.com/prettier/eslint-plugin-prettier
"prettier/prettier": "warn",
},
};
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"quoteProps": "consistent",
"trailingComma": "es5"
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
},
"devDependencies": {
"@types/node": "^16.11.7",
"eslint": "^8.5.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-prettier": "^4.0.0",
"webpack": "^5.65.0"
}
}
21 changes: 11 additions & 10 deletions src/helpers/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const _RUNTIME_ENV_MAPPINGS = {
all: "CF_ON_INVALID_FLAG_STOPPROCESSING",
},

//parallel request wait timeout for download blocklist from s3
// parallel request wait timeout for download blocklist from s3
fetchTimeout: {
type: "number",
all: "CF_BLOCKLIST_DOWNLOAD_TIMEOUT",
},

//env variables for td file split
// env variables for td file split
tdNodecount: {
type: "number",
all: "TD_NODE_COUNT",
Expand All @@ -50,9 +50,9 @@ const _RUNTIME_ENV_MAPPINGS = {
all: "TD_PARTS",
},

//set to on - off aggressive cache plugin
//as of now Cache-api is available only on worker
//so _getRuntimeEnv will set this to false for other runtime.
// set to on - off aggressive cache plugin
// as of now Cache-api is available only on worker
// so _getRuntimeEnv will set this to false for other runtime.
isAggCacheReq: {
type: "boolean",
worker: "IS_AGGRESSIVE_CACHE_REQ",
Expand All @@ -62,7 +62,7 @@ const _RUNTIME_ENV_MAPPINGS = {
/**
* Get runtime specific environment variables.
* @param {String} runtime - Runtime name (deno, node, worker).
* @returns {Object} Runtime environment variables.
* @return {Object} Runtime environment variables.
*/
function _getRuntimeEnv(runtime) {
console.info("Loading env. from runtime:", runtime);
Expand Down Expand Up @@ -123,7 +123,8 @@ export default class EnvManager {
this.envMap.set(key, value);
}

//adding download timeout with worker time to determine worker's overall timeout
// adding download timeout with worker time to determine worker's overall
// timeout
runtime == "worker" &&
this.envMap.set(
"workerTimeout",
Expand All @@ -141,22 +142,22 @@ export default class EnvManager {
}

/**
* @returns {Map} - Map of env variables.
* @return {Map} - Map of env variables.
*/
getMap() {
return this.envMap;
}

/**
* @returns {Object} - Object of currently loaded env variables.
* @return {Object} - Object of currently loaded env variables.
*/
toObject() {
return Object.fromEntries(this.envMap);
}

/**
* @param {String} key - env variable name
* @returns {*} - env variable value
* @return {*} - env variable value
*/
get(key) {
return this.envMap.get(key);
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/envutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*/

export function isWorkers() {
return env && env.runTime === "worker"
return env && env.runTime === "worker";
}

export function isNode() {
return env && env.runTime === "node"
return env && env.runTime === "node";
}

export function workersTimeout(defaultValue = 0) {
if (envManager) return envManager.get("workerTimeout") || defaultValue
return defaultValue
if (envManager) return envManager.get("workerTimeout") || defaultValue;
return defaultValue;
}
3 changes: 2 additions & 1 deletion src/helpers/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export default class Log {
_LOG_LEVELS.get(level) < _LOG_LEVELS.get(console.level)
) {
throw new Error(
`Cannot set (log.level='${level}') < (console.level = '${console.level}')`
"Cannot set " +
`(log.level='${level}') < (console.level = '${console.level}')`
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/helpers/node/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param {String} TLS_CRT_KEY - Contains base64 (no wrap) encoded key and
* certificate files seprated by a newline (\n) and described by `KEY=` and
* `CRT=` respectively. Ex: `TLS_="KEY=encoded_string\nCRT=encoded_string"`
* @returns [TLS_KEY, TLS_CRT]
* @return {Array<Buffer>} [TLS_KEY, TLS_CRT]
*/
export function getTLSfromEnv(TLS_CRT_KEY) {
if (TLS_CRT_KEY == undefined) throw new Error("TLS cert / key not found");
Expand All @@ -22,7 +22,7 @@ export function getTLSfromEnv(TLS_CRT_KEY) {

/**
* @param {Object} headers
* @returns
* @return {Object}
*/
export function copyNonPseudoHeaders(headers) {
const resH = {};
Expand All @@ -38,7 +38,7 @@ export function copyNonPseudoHeaders(headers) {

/**
* @param {Object} headers
* @returns
* @return {Object}
*/
export function transformPseudoHeaders(headers) {
const resH = {};
Expand Down

0 comments on commit 2a800fc

Please sign in to comment.