Skip to content

Commit

Permalink
Merge pull request #397 from openaddresses/lints
Browse files Browse the repository at this point in the history
Add Lint Update
  • Loading branch information
ingalls authored Aug 22, 2024
2 parents b3bf389 + d68e23d commit f587341
Show file tree
Hide file tree
Showing 22 changed files with 4,291 additions and 2,834 deletions.
52 changes: 0 additions & 52 deletions .eslintrc.json

This file was deleted.

56 changes: 0 additions & 56 deletions api/.eslintrc.json

This file was deleted.

38 changes: 38 additions & 0 deletions api/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import js from "@eslint/js";
import nodePlugin from "eslint-plugin-n";

export default [
js.configs.recommended,
nodePlugin.configs["flat/recommended-module"],
{
"rules": {
"no-console": 0,
"arrow-parens": [ "error", "always" ],
"no-var": "error",
"prefer-const": "error",
"array-bracket-spacing": [ "error", "never" ],
"comma-dangle": [ "error", "never" ],
"computed-property-spacing": [ "error", "never" ],
"eol-last": "error",
"eqeqeq": [ "error", "smart" ],
"indent": [ "error", 4, { "SwitchCase": 1 } ],
"no-confusing-arrow": [ "error", { "allowParens": false } ],
"no-extend-native": "error",
"no-mixed-spaces-and-tabs": "error",
"func-call-spacing": [ "error", "never" ],
"no-trailing-spaces": "error",
"no-unused-vars": "error",
"no-use-before-define": [ "error", "nofunc" ],
"object-curly-spacing": [ "error", "always" ],
"prefer-arrow-callback": "error",
"quotes": [ "error", "single", "avoid-escape" ],
"semi": [ "error", "always" ],
"space-infix-ops": "error",
"spaced-comment": [ "error", "always" ],
"keyword-spacing": [ "error", { "before": true, "after": true } ],
"template-curly-spacing": [ "error", "never" ],
"semi-spacing": "error",
"strict": "error",
}
}
]
4 changes: 3 additions & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ try {

Object.assign(process.env, JSON.parse(String(fs.readFileSync(dotfile))));
} catch (err) {
console.log('ok - no .env file loaded');
console.log(`ok - no .env file loaded: ${String(err)}`);
}

const pkg = JSON.parse(String(fs.readFileSync(new URL('./package.json', import.meta.url))));
Expand All @@ -45,6 +45,7 @@ async function configure(args) {
return server(await Config.env(args));
} catch (err) {
console.error(err);
// eslint-disable-next-line n/no-process-exit
process.exit(1);
}
}
Expand Down Expand Up @@ -190,6 +191,7 @@ export default async function server(config) {
req.token = await user.user(decoded.u);
req.token.type = 'token';
} catch (err) {
console.error(err);
// Login/Verify uses non-jwt token
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions api/lib/cacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class Cacher {

return cached;
} catch (err) {
console.error(err);
if (res) return res;

const fresh = await miss();
Expand Down Expand Up @@ -100,6 +101,7 @@ export default class Cacher {
try {
await this.cache.flush();
} catch (err) {
console.error(err);
throw new Error('Failed to flush cache');
}
}
Expand Down
5 changes: 3 additions & 2 deletions api/lib/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class CI {
*
* @param {String} ref Github Ref
*/
// eslint-disable-next-line no-use-before-define

async filediff(ref) {
console.error(`ok - FileDiff: ${ref}`);

Expand All @@ -224,7 +224,7 @@ export default class CI {
* Given a list of filediffs, calculate what sources in the JSON file changed
* @param {Object[]} files
*/
// eslint-disable-next-line no-use-before-define

static async internaldiff(files) {
const jobs = [];

Expand Down Expand Up @@ -295,6 +295,7 @@ export default class CI {
try {
assert.deepEqual(master_sources[branch], branch_sources[branch]);
} catch (err) {
console.error(err);
jobs.push({
source: file.raw,
layer: branch_sources[branch]._layer,
Expand Down
1 change: 0 additions & 1 deletion api/lib/types/collections.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import Err from '@openaddresses/batch-error';
import Generic from '@openaddresses/batch-generic';
import { sql } from 'slonik';
Expand Down
1 change: 0 additions & 1 deletion api/lib/types/data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Err from '@openaddresses/batch-error';
import Generic from '@openaddresses/batch-generic';
import Map from './map.js';
import fs from 'fs';
import moment from 'moment';
import { sql } from 'slonik';

Expand Down
5 changes: 2 additions & 3 deletions api/lib/types/exporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import Err from '@openaddresses/batch-error';
import Generic from '@openaddresses/batch-generic';
import { Status } from '../util.js';
Expand Down Expand Up @@ -42,15 +41,15 @@ export default class Exporter extends Generic {
try {
query.after = moment(query.after);
} catch (err) {
throw new Err(400, null, 'after param is not recognized as a valid date');
throw new Err(400, err, 'after param is not recognized as a valid date');
}
}

if (query.before) {
try {
query.before = moment(query.before);
} catch (err) {
throw new Err(400, null, 'before param is not recognized as a valid date');
throw new Err(400, err, 'before param is not recognized as a valid date');
}
}

Expand Down
5 changes: 2 additions & 3 deletions api/lib/types/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Job extends Generic {
* @param {String} [query.source=Null] - Filter results by source
* @param {String[]} [query.status=["Success", "Fail", "Pending", "Warn"]] - Only show jobs with given status
*/
static async list(pool, query={}) {
static async list(pool, query = {}) {
query.limit = Params.integer(query.limit, { default: 100 });
query.page = Params.integer(query.page, { default: 0 });
query.source = Params.string(query.source, { default: '' });
Expand Down Expand Up @@ -235,6 +235,7 @@ export default class Job extends Generic {
try {
job.license = JSON.parse(job.license);
} catch (err) {
console.error(err);
job.license = true;
}
}
Expand Down Expand Up @@ -289,8 +290,6 @@ export default class Job extends Generic {
}

static async generate(pool, job) {
let pgres;

if (!job.output) {
job.output = {
cache: false,
Expand Down
5 changes: 2 additions & 3 deletions api/lib/types/joberror.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Err from '@openaddresses/batch-error';
import Job from './job.js';
import Run from './run.js';
import fs from 'fs';
import { sql } from 'slonik';
import { Status } from '../util.js';
import Generic, { Params } from '@openaddresses/batch-generic';
Expand Down Expand Up @@ -59,14 +58,14 @@ export default class JobError extends Generic {
throw new Err(500, err, 'Failed to list job_errors');
}

return this.deserialize_list(pgres, 'errors')
return this.deserialize_list(pgres, 'errors');
}

serialize() {
const json = super.serialize();

if (this.message && !json.messages) {
json.messages = [ this.message ];
json.messages = [this.message];
delete json.message;
} else if (this.messages) {
json.messages = this.messages;
Expand Down
1 change: 0 additions & 1 deletion api/lib/types/level-override.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import Err from '@openaddresses/batch-error';
import Generic from '@openaddresses/batch-generic';
import { sql } from 'slonik';
Expand Down
7 changes: 3 additions & 4 deletions api/lib/types/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import Err from '@openaddresses/batch-error';
import Generic, { Params } from '@openaddresses/batch-generic';
import moment from 'moment';
Expand Down Expand Up @@ -89,15 +88,15 @@ export default class Run extends Generic {
try {
query.after = moment(query.after);
} catch (err) {
throw new Err(400, null, 'after param is not recognized as a valid date');
throw new Err(400, err, 'after param is not recognized as a valid date');
}
}

if (query.before) {
try {
query.before = moment(query.before);
} catch (err) {
throw new Err(400, null, 'before param is not recognized as a valid date');
throw new Err(400, err, 'before param is not recognized as a valid date');
}
}

Expand Down Expand Up @@ -212,7 +211,7 @@ export default class Run extends Generic {
source: jobs[i].source,
layer: jobs[i].layer,
name: jobs[i].name
})
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions api/lib/types/token.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import moment from 'moment';
import Data from './data.js';
import Err from '@openaddresses/batch-error';
import Generic from '@openaddresses/batch-generic';
import { sql } from 'slonik';
Expand Down
Loading

0 comments on commit f587341

Please sign in to comment.