From f6f5b5105a4daf378a30c3cd8fa4b3a57c7c102c Mon Sep 17 00:00:00 2001 From: Michael Levin Date: Fri, 1 Mar 2024 11:22:28 -0500 Subject: [PATCH] Further improve linting Add eslint recommended configs, fix lint issues flagged throughout the repo --- eslint.config.js | 15 ++++- index.js | 2 +- ...170316115145_add_analytics_data_indexes.js | 2 +- ...20170522094056_rename_date_time_to_date.js | 4 +- ...10706213753_add_date_id_multi_col_index.js | 2 +- package-lock.json | 58 +++++++++++++++---- package.json | 2 + src/db.js | 2 - src/logger.js | 1 - test/app.test.js | 7 ++- 10 files changed, 73 insertions(+), 22 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index b31c548..4431d7f 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,3 +1,16 @@ +const { configs: eslintConfigs } = require("@eslint/js"); const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended"); +const globals = require("globals"); -module.exports = [eslintPluginPrettierRecommended]; +module.exports = [ + { + languageOptions: { + globals: { + ...globals.node, + ...globals.mocha, + }, + }, + }, + eslintConfigs.recommended, + eslintPluginPrettierRecommended, +]; diff --git a/index.js b/index.js index be16b26..ff1f142 100644 --- a/index.js +++ b/index.js @@ -8,5 +8,5 @@ const config = require("./src/config"); const logger = require("./src/logger"); app.listen(config.port, () => { - console.log(`Listening on ${config.port}`); + logger.info(`Listening on ${config.port}`); }); diff --git a/migrations/20170316115145_add_analytics_data_indexes.js b/migrations/20170316115145_add_analytics_data_indexes.js index 07ef5ea..82a9c8c 100644 --- a/migrations/20170316115145_add_analytics_data_indexes.js +++ b/migrations/20170316115145_add_analytics_data_indexes.js @@ -10,7 +10,7 @@ exports.up = function (knex) { }); }; -exports.down = function (knex, Promise) { +exports.down = function (knex) { return knex.schema.table("analytics_data", (table) => { table.dropIndex(["report_name", "report_agency"]); table.dropIndex("date_time", "analytics_data_date_time_desc"); diff --git a/migrations/20170522094056_rename_date_time_to_date.js b/migrations/20170522094056_rename_date_time_to_date.js index 78a2144..4ab221d 100644 --- a/migrations/20170522094056_rename_date_time_to_date.js +++ b/migrations/20170522094056_rename_date_time_to_date.js @@ -1,4 +1,4 @@ -exports.up = function (knex, Promise) { +exports.up = function (knex) { return knex.schema .raw("ALTER TABLE analytics_data RENAME COLUMN date_time TO date") .then(() => { @@ -8,7 +8,7 @@ exports.up = function (knex, Promise) { }); }; -exports.down = function (knex, Promise) { +exports.down = function (knex) { return knex.schema .raw("ALTER TABLE analytics_data RENAME COLUMN date TO date_time") .then(() => { diff --git a/migrations/20210706213753_add_date_id_multi_col_index.js b/migrations/20210706213753_add_date_id_multi_col_index.js index 891ac52..2de7dd1 100644 --- a/migrations/20210706213753_add_date_id_multi_col_index.js +++ b/migrations/20210706213753_add_date_id_multi_col_index.js @@ -4,7 +4,7 @@ exports.up = function (knex) { ); }; -exports.down = function (knex, Promise) { +exports.down = function (knex) { return knex.schema.table("analytics_data", (table) => { table.dropIndex("analytics_data_date_desc_id_asc"); }); diff --git a/package-lock.json b/package-lock.json index c21180f..ca2d3ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,11 +19,13 @@ "winston": "^3.11.0" }, "devDependencies": { + "@eslint/js": "^8.57.0", "chai": "^4.3.10", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", "extend": ">= 3.0.2", + "globals": "^14.0.0", "mocha": "^10.2.0", "nodemon": "^3.0.1", "proxyquire": "^2.1.3", @@ -732,10 +734,25 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/js": { - "version": "8.56.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz", - "integrity": "sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==", + "version": "8.57.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", + "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2696,6 +2713,30 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/@eslint/js": { + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz", + "integrity": "sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/eslint/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/esm": { "version": "3.2.25", "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", @@ -3310,15 +3351,12 @@ } }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" diff --git a/package.json b/package.json index 9cc6c7e..2670052 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,13 @@ }, "homepage": "https://github.com/18F/analytics-reporter-api#readme", "devDependencies": { + "@eslint/js": "^8.57.0", "chai": "^4.3.10", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", "extend": ">= 3.0.2", + "globals": "^14.0.0", "mocha": "^10.2.0", "nodemon": "^3.0.1", "proxyquire": "^2.1.3", diff --git a/src/db.js b/src/db.js index 44be3c5..099d154 100644 --- a/src/db.js +++ b/src/db.js @@ -9,8 +9,6 @@ const parseLimitParam = (limitParam) => { if (limit > 10000 || limit <= 0) { return 10000; - } else if (limit <= 0) { - return 1000; } return limit; }; diff --git a/src/logger.js b/src/logger.js index 86416ff..c86f38b 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,6 +1,5 @@ const expressWinston = require("express-winston"); const winston = require("winston"); -const config = require("./config"); const logger = expressWinston.logger({ transports: [new winston.transports.Console()], diff --git a/test/app.test.js b/test/app.test.js index 8de5b26..fdfbbc4 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -262,23 +262,24 @@ describe(`app with unspupported version`, () => { }); it("should not accept unsupported versions", (done) => { + const unsupportedVersion = "v2.x"; + db.query = (params) => { expect(params.reportAgency).to.equal("fake-agency"); expect(params.reportName).to.equal("fake-report"); - const arr = handleIfRouteNotice(route, [ + const arr = handleIfRouteNotice(unsupportedVersion, [ { id: 1, date: new Date("2017-01-01") }, { id: 2, date: new Date("2017-01-02") }, ]); return Promise.resolve(arr); }; - const unspupportedVersion = "v2.x"; const expectedErrorMessage = "Version not found. Visit https://analytics.usa.gov/developer for information on the latest supported version."; const dataRequest = request(app) .get( - `/${unspupportedVersion}/agencies/fake-agency/reports/fake-report/data`, + `/${unsupportedVersion}/agencies/fake-agency/reports/fake-report/data`, ) .expect(404);