From 35b9a6cd3a7475e1a134a3de58d2225af1e0e052 Mon Sep 17 00:00:00 2001 From: viveksharmaui Date: Fri, 3 Apr 2020 22:34:20 +0500 Subject: [PATCH 1/2] ADD: eslint configurations --- .eslintrc.json | 28 ++++++++++++++++++++++++++++ package.json | 4 ++++ utils/cli.js | 7 ++++--- utils/getCountries.js | 5 +++-- utils/getCountry.js | 3 ++- utils/getCountryChart.js | 8 ++++---- utils/getStates.js | 5 +++-- utils/init.js | 2 +- utils/table.js | 9 +++++---- utils/theEnd.js | 5 +++-- 10 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..280f89d --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,28 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es6": true + }, + "extends": ["airbnb-standard"], + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parserOptions": { + "ecmaVersion": 2018 + }, + "rules": { + "indent": [2, "tab"], + "no-tabs": 0, + "no-console": 0, + "consistent-return": 0, + "array-callback-return": 0, + "import/order": 0, + "no-undef": 0, + "no-const-assign": 0, + "no-unused-vars": 0, + "no-param-reassign": 0, + "promise/param-names": 0 + } +} diff --git a/package.json b/package.json index 698f077..3e9d970 100644 --- a/package.json +++ b/package.json @@ -61,10 +61,14 @@ "update-notifier": "^4.1.0" }, "devDependencies": { + "eslint": "^6.8.0", + "eslint-config-airbnb-standard": "^3.1.0", "prettier": "^2.0.2" }, "scripts": { "format": "prettier --write \"./**/*.{js,json}\"", + "lint": "eslint ./utils/", + "lint:fix": "eslint ./utils/ --fix", "test": "node test.js" } } diff --git a/utils/cli.js b/utils/cli.js index 0efdad0..cd25d75 100644 --- a/utils/cli.js +++ b/utils/cli.js @@ -1,8 +1,9 @@ const meow = require('meow'); const chalk = require('chalk'); -const green = chalk.green; -const yellow = chalk.yellow; -const cyan = chalk.cyan; + +const { green } = chalk; +const { yellow } = chalk; +const { cyan } = chalk; module.exports = meow( ` diff --git a/utils/getCountries.js b/utils/getCountries.js index 31cf9e5..622f9f7 100644 --- a/utils/getCountries.js +++ b/utils/getCountries.js @@ -1,7 +1,8 @@ const axios = require('axios'); const chalk = require('chalk'); -const cyan = chalk.cyan; -const dim = chalk.dim; + +const { cyan } = chalk; +const { dim } = chalk; const comma = require('comma-number'); const { sortingKeys } = require('./table.js'); const to = require('await-to-js').default; diff --git a/utils/getCountry.js b/utils/getCountry.js index 74aa818..b10b96d 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -2,7 +2,8 @@ const chalk = require('chalk'); const axios = require('axios'); const sym = require('log-symbols'); const comma = require('comma-number'); -const red = chalk.red; + +const { red } = chalk; const to = require('await-to-js').default; const handleError = require('cli-handle-error'); diff --git a/utils/getCountryChart.js b/utils/getCountryChart.js index 868000a..a3edd70 100644 --- a/utils/getCountryChart.js +++ b/utils/getCountryChart.js @@ -26,7 +26,7 @@ module.exports = async (spinner, countryName, { chart, log }) => { logScale = x => (x === 0 ? undefined : Math.log(x)); } const shortDate = x => moment(x, 'MM/DD/YY').format('D MMM'); - const cumulative = (a, b) => (a = a + b); + const cumulative = (a, b) => (a += b); const screen = blessed.screen(); const line = contrib.line({ style: { @@ -76,9 +76,9 @@ module.exports = async (spinner, countryName, { chart, log }) => { line.setData([casesSeries, deathsSeries, recoveredSeries]); screen.render(); await new Promise((resolve, _) => { - screen.key(['escape', 'q', 'C-c', 'enter', 'space'], (ch, key) => { - return process.exit(0); - }); + screen.key(['escape', 'q', 'C-c', 'enter', 'space'], (ch, key) => + process.exit(0) + ); }); } }; diff --git a/utils/getStates.js b/utils/getStates.js index 4eaee68..a12ec89 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -1,7 +1,8 @@ const axios = require('axios'); const chalk = require('chalk'); -const cyan = chalk.cyan; -const dim = chalk.dim; + +const { cyan } = chalk; +const { dim } = chalk; const comma = require('comma-number'); const { sortingStateKeys } = require('./table.js'); const to = require('await-to-js').default; diff --git a/utils/init.js b/utils/init.js index 50101bf..1e2e831 100644 --- a/utils/init.js +++ b/utils/init.js @@ -1,8 +1,8 @@ const welcome = require('cli-welcome'); const checkNode = require('cli-check-node'); -const pkgJSON = require('./../package.json'); const updateNotifier = require('update-notifier'); const unhandledError = require('cli-handle-unhandled'); +const pkgJSON = require('./../package.json'); module.exports = async () => { unhandledError(); diff --git a/utils/table.js b/utils/table.js index 6a410b6..648f652 100644 --- a/utils/table.js +++ b/utils/table.js @@ -1,8 +1,9 @@ const chalk = require('chalk'); -const green = chalk.green; -const red = chalk.red; -const yellow = chalk.yellow; -const dim = chalk.dim; + +const { green } = chalk; +const { red } = chalk; +const { yellow } = chalk; +const { dim } = chalk; module.exports = { single: [ diff --git a/utils/theEnd.js b/utils/theEnd.js index 91c4554..c172885 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -1,7 +1,8 @@ const sym = require('log-symbols'); const chalk = require('chalk'); -const cyan = chalk.cyan; -const dim = chalk.dim; + +const { cyan } = chalk; +const { dim } = chalk; const infoStates = () => console.log( From 14fe3c6b25ddc801c9dc36a73bd28786d9f7dbec Mon Sep 17 00:00:00 2001 From: viveksharmaui Date: Fri, 3 Apr 2020 22:41:01 +0500 Subject: [PATCH 2/2] ADD: eslint security --- .eslintrc.json | 8 ++++++-- package.json | 1 + utils/getCountryChart.js | 4 +--- utils/theEnd.js | 14 ++++++-------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 280f89d..6b50db3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,10 @@ "commonjs": true, "es6": true }, - "extends": ["airbnb-standard"], + "plugins": [ + "security" + ], + "extends": ["airbnb-standard","plugin:security/recommended"], "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" @@ -23,6 +26,7 @@ "no-const-assign": 0, "no-unused-vars": 0, "no-param-reassign": 0, - "promise/param-names": 0 + "promise/param-names": 0, + "security/detect-object-injection":0 } } diff --git a/package.json b/package.json index 3e9d970..3c10ea7 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "devDependencies": { "eslint": "^6.8.0", "eslint-config-airbnb-standard": "^3.1.0", + "eslint-plugin-security": "^1.4.0", "prettier": "^2.0.2" }, "scripts": { diff --git a/utils/getCountryChart.js b/utils/getCountryChart.js index a3edd70..6d910c4 100644 --- a/utils/getCountryChart.js +++ b/utils/getCountryChart.js @@ -76,9 +76,7 @@ module.exports = async (spinner, countryName, { chart, log }) => { line.setData([casesSeries, deathsSeries, recoveredSeries]); screen.render(); await new Promise((resolve, _) => { - screen.key(['escape', 'q', 'C-c', 'enter', 'space'], (ch, key) => - process.exit(0) - ); + screen.key(['escape', 'q', 'C-c', 'enter', 'space'], (ch, key) => process.exit(0)); }); } }; diff --git a/utils/theEnd.js b/utils/theEnd.js index c172885..5bcaf83 100644 --- a/utils/theEnd.js +++ b/utils/theEnd.js @@ -4,9 +4,8 @@ const chalk = require('chalk'); const { cyan } = chalk; const { dim } = chalk; -const infoStates = () => - console.log( - dim(` +const infoStates = () => console.log( + dim(` \n${sym.info} ${cyan(`KEY:`)} ${dim(`❯ `)}${cyan(`State:`)} Name of the state ${dim(`❯ `)}${cyan(`Cases:`)} Total number of cases in a country @@ -16,11 +15,10 @@ ${dim(`❯ `)}${cyan(`Deaths (today):`)} Deaths in 24 hours GMT/UTC ${dim(`❯ `)}${cyan(`Recovered:`)} Total number of recovered people ${dim(`❯ `)}${cyan(`Active:`)} Total number of active patients `) - ); +); -const infoCountries = () => - console.log( - dim(` +const infoCountries = () => console.log( + dim(` \n${sym.info} ${cyan(`KEY:`)} ${dim(`❯ `)}${cyan(`Country:`)} Name of the country ${dim(`❯ `)}${cyan(`Cases:`)} Total number of cases in a country @@ -32,7 +30,7 @@ ${dim(`❯ `)}${cyan(`Active:`)} Total number of active patients ${dim(`❯ `)}${cyan(`Critical:`)} Total number of critical patients ${dim(`❯ `)}${cyan(`Per Million:`)} Affected patients per million `) - ); +); module.exports = async (lastUpdated, states, minimal) => { if (minimal) return console.log();