Skip to content

Commit

Permalink
Further improve linting
Browse files Browse the repository at this point in the history
Add eslint recommended configs, fix lint issues flagged throughout the repo
  • Loading branch information
levinmr committed Mar 1, 2024
1 parent 6997746 commit f6f5b51
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 22 deletions.
15 changes: 14 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -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,
];
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
2 changes: 1 addition & 1 deletion migrations/20170316115145_add_analytics_data_indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions migrations/20170522094056_rename_date_time_to_date.js
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion migrations/20210706213753_add_date_id_multi_col_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down
58 changes: 48 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const parseLimitParam = (limitParam) => {

if (limit > 10000 || limit <= 0) {
return 10000;
} else if (limit <= 0) {
return 1000;
}
return limit;
};
Expand Down
1 change: 0 additions & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
@@ -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()],
Expand Down
7 changes: 4 additions & 3 deletions test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f6f5b51

Please sign in to comment.