diff --git a/.dockerignore b/.dockerignore index aed7eae467..4914fe6fc8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,7 @@ .vscode .prettierrc .prettierignore +.eslintrc.cjs node_modules/ worker/ @@ -16,3 +17,4 @@ log/ *.md LICENSE wrangler.toml +package-lock.json diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000000..0f95ec7e72 --- /dev/null +++ b/.eslintrc.cjs @@ -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", + }, +}; diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index c30a0d1e5a..0000000000 --- a/.prettierrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "tabWidth": 2, - "printWidth": 80, - "trailingComma": "es5", - "semi": true -} diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000000..b1062dcf72 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,8 @@ +{ + "printWidth": 80, + "tabWidth": 2, + "semi": true, + "singleQuote": false, + "quoteProps": "consistent", + "trailingComma": "es5" +} diff --git a/package.json b/package.json index 4da836cbb8..474595791f 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/helpers/env.js b/src/helpers/env.js index ea1e2c8060..04eceb0543 100644 --- a/src/helpers/env.js +++ b/src/helpers/env.js @@ -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", @@ -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", @@ -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); @@ -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", @@ -141,14 +142,14 @@ 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); @@ -156,7 +157,7 @@ export default class EnvManager { /** * @param {String} key - env variable name - * @returns {*} - env variable value + * @return {*} - env variable value */ get(key) { return this.envMap.get(key); diff --git a/src/helpers/envutil.js b/src/helpers/envutil.js index b79b7278dc..c4a3c9880b 100644 --- a/src/helpers/envutil.js +++ b/src/helpers/envutil.js @@ -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; } diff --git a/src/helpers/log.js b/src/helpers/log.js index 2154d6c13f..06153bd87d 100644 --- a/src/helpers/log.js +++ b/src/helpers/log.js @@ -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}')` ); } diff --git a/src/helpers/node/util.js b/src/helpers/node/util.js index 250a1d7bde..e4de198c8a 100644 --- a/src/helpers/node/util.js +++ b/src/helpers/node/util.js @@ -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} [TLS_KEY, TLS_CRT] */ export function getTLSfromEnv(TLS_CRT_KEY) { if (TLS_CRT_KEY == undefined) throw new Error("TLS cert / key not found"); @@ -22,7 +22,7 @@ export function getTLSfromEnv(TLS_CRT_KEY) { /** * @param {Object} headers - * @returns + * @return {Object} */ export function copyNonPseudoHeaders(headers) { const resH = {}; @@ -38,7 +38,7 @@ export function copyNonPseudoHeaders(headers) { /** * @param {Object} headers - * @returns + * @return {Object} */ export function transformPseudoHeaders(headers) { const resH = {};