Skip to content

Commit

Permalink
Code style / linting
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jan 18, 2024
1 parent 151ba9a commit 8628422
Show file tree
Hide file tree
Showing 90 changed files with 788 additions and 747 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,42 @@ rules:
- error
- allowModules:
- restify-errors
no-constant-condition:
- error
- checkLoops: false
no-template-curly-in-string: error
block-scoped-var: error
no-unreachable-loop: error
require-atomic-updates: warn
max-classes-per-file: error
no-alert: error
no-caller: error
eqeqeq: error
no-constructor-return: error
no-eval: error
no-extend-native: error
no-extra-bind: error
no-implicit-coercion: error
no-invalid-this: error
no-multi-spaces: error
no-multi-str: error
no-return-assign: error
no-self-compare: error
no-sequences: error
no-throw-literal: error
no-unmodified-loop-condition: error
no-unused-expressions: error
no-useless-call: error
no-useless-concat: error
no-useless-return: error
no-void: error
no-warning-comments: warn
radix: error
no-shadow: error
no-use-before-define:
- error
- functions: false
arrow-spacing: error
no-confusing-arrow: error
no-duplicate-imports: error
no-var: error
10 changes: 4 additions & 6 deletions src/api/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class CapabilitiesAPI {

addEndpoint(method, path) {
method = method.toUpperCase();
for(let i in this.endpoints) {
if (this.endpoints[i].path == path) {
for(const i in this.endpoints) {
if (this.endpoints[i].path === path) {
this.endpoints[i].methods.push(method);
return;
}
Expand All @@ -36,15 +36,13 @@ export default class CapabilitiesAPI {
}

async getVersions(req, res) {
var versions = this.context.otherVersions.slice(0); // Make sure to clone it
const versions = this.context.otherVersions.slice(0); // Make sure to clone it
versions.push({
url: Utils.getApiUrl(),
production: this.context.production,
api_version: this.context.apiVersion
});
res.json({
versions: versions
});
res.json({ versions });
}

async getCapabilities(req, res) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Data {
rel: 'alternate',
type: 'application/json',
title: 'Machine-readable Earth Engine Data Catalog'
},
};
this.geeBrowsableCatalogLink = {
rel: 'alternate',
href: 'https://developers.google.com/earth-engine/datasets/catalog/',
Expand Down
16 changes: 8 additions & 8 deletions src/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export default class FilesAPI {
}

async beforeServerStart(server) {
var pathRoutes = ['/files/{path}', '/files/*'];
const pathRoutes = ['/files/{path}', '/files/*'];
server.addEndpoint('get', '/files', this.getFiles.bind(this));
server.addEndpoint('get', pathRoutes, this.getFileByPath.bind(this));
server.addEndpoint('put', pathRoutes, this.putFileByPath.bind(this));
server.addEndpoint('delete', pathRoutes, this.deleteFileByPath.bind(this));
}

init(req, path = null) {
init(req, location = null) {
if (!req.user._id) {
throw new Errors.AuthenticationRequired();
}
const p = this.workspace.getPathFromRequest(req, path);
const p = this.workspace.getPathFromRequest(req, location);
if (!p) {
throw new Errors.FilePathInvalid();
}
Expand Down Expand Up @@ -65,14 +65,14 @@ export default class FilesAPI {
await fse.ensureDir(path.dirname(p));
}

let octetStream = 'application/octet-stream';
const octetStream = 'application/octet-stream';
if (req.contentType() !== octetStream) {
throw new Errors.ContentTypeInvalid({types: octetStream});
}

const cleanUp = async (p) => {
if (await fse.exists(p)) {
await fse.unlink(p);
const cleanUp = async (filepath) => {
if (await fse.exists(filepath)) {
await fse.unlink(filepath);
}
};

Expand Down Expand Up @@ -126,7 +126,7 @@ export default class FilesAPI {
const p = this.init(req);
await HttpUtils.isFile(p);
await new Promise((resolve, reject) => {
let stream = fse.createReadStream(p);
const stream = fse.createReadStream(p);
res.setHeader('Content-Type', 'application/octet-stream');
stream.pipe(res);
stream.on('error', reject);
Expand Down
35 changes: 18 additions & 17 deletions src/api/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class JobsAPI {
}

async getTempFile(req, res) {
var p = this.storage.makeFolder(this.context.getTempFolder(), [req.params.token, req.params.file]);
const p = this.storage.makeFolder(this.context.getTempFolder(), [req.params.token, req.params.file]);
if (!p) {
throw new Errors.NotFound();
}
Expand All @@ -55,12 +55,12 @@ export default class JobsAPI {
await this.deliverFile(res, p);
}

async deliverFile(res, path) {
await HttpUtils.isFile(path);
async deliverFile(res, filepath) {
await HttpUtils.isFile(filepath);

res.header('Content-Type', Utils.extensionToMediaType(path));
res.header('Content-Type', Utils.extensionToMediaType(filepath));
return await new Promise((resolve, reject) => {
var stream = fse.createReadStream(path);
const stream = fse.createReadStream(filepath);
stream.pipe(res);
stream.on('error', reject);
stream.on('close', () => {
Expand Down Expand Up @@ -108,8 +108,8 @@ export default class JobsAPI {
}

async getResultLogs(user_id, id, log_level) {
let file = path.normalize(path.join('./storage/user_files/', user_id, 'sync_logs' , id + '.logs.db'));
let logs = new Logs(file, Utils.getApiUrl('/result/logs/' + id), log_level);
const file = path.normalize(path.join('./storage/user_files/', user_id, 'sync_logs' , id + '.logs.db'));
const logs = new Logs(file, Utils.getApiUrl('/result/logs/' + id), log_level);
await logs.init();
return logs;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ export default class JobsAPI {
await this.storage.updateJobStatus(query, 'running');

const context = this.context.processingContext(req);
var pg = new ProcessGraph(job.process, context);
const pg = new ProcessGraph(job.process, context);
pg.setLogger(logger);

const resultNode = await pg.execute();
Expand All @@ -192,7 +192,7 @@ export default class JobsAPI {
});

const extension = context.getExtension(cube.getOutputFormat());
const filePath = this.storage.getJobFile(job._id, Utils.generateHash() + "." + extension);
const filePath = this.storage.getJobFile(job._id, Utils.generateHash() + "." + extension);
logger.debug("Storing result to: " + filePath);
await fse.ensureDir(path.dirname(filePath));
await new Promise((resolve, reject) => {
Expand All @@ -212,7 +212,7 @@ export default class JobsAPI {
}

async getJobResultsByToken(req, res) {
var query = {
const query = {
token: req.params.token
};

Expand All @@ -222,7 +222,7 @@ export default class JobsAPI {
async getJobResults(req, res) {
this.init(req);

var query = {
const query = {
_id: req.params.job_id,
user_id: req.user._id
};
Expand Down Expand Up @@ -324,14 +324,15 @@ export default class JobsAPI {

const data = {};
const promises = [];
for(let key in req.body) {
for(const key in req.body) {
if (this.storage.isFieldEditable(key)) {
switch(key) {
case 'process':
var pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
case 'process': {
const pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
pg.allowUndefinedParameters(false);
promises.push(pg.validate());
break;
}
default:
// ToDo: Validate further data #73

Check warning on line 337 in src/api/jobs.js

View workflow job for this annotation

GitHub Actions / deploy (17)

Unexpected 'todo' comment: 'ToDo: Validate further data #73'

Check warning on line 337 in src/api/jobs.js

View workflow job for this annotation

GitHub Actions / deploy (lts/*)

Unexpected 'todo' comment: 'ToDo: Validate further data #73'

Check warning on line 337 in src/api/jobs.js

View workflow job for this annotation

GitHub Actions / deploy (latest)

Unexpected 'todo' comment: 'ToDo: Validate further data #73'
// For example, if budget < costs, reject request
Expand Down Expand Up @@ -367,12 +368,12 @@ export default class JobsAPI {
throw new Errors.RequestBodyMissing();
}

var pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
const pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
pg.allowUndefinedParameters(false);
await pg.validate();

// ToDo: Validate further data #73

Check warning on line 375 in src/api/jobs.js

View workflow job for this annotation

GitHub Actions / deploy (17)

Unexpected 'todo' comment: 'ToDo: Validate further data #73'

Check warning on line 375 in src/api/jobs.js

View workflow job for this annotation

GitHub Actions / deploy (lts/*)

Unexpected 'todo' comment: 'ToDo: Validate further data #73'

Check warning on line 375 in src/api/jobs.js

View workflow job for this annotation

GitHub Actions / deploy (latest)

Unexpected 'todo' comment: 'ToDo: Validate further data #73'
var data = {
const data = {
title: req.body.title || null,
description: req.body.description || null,
process: req.body.process,
Expand Down Expand Up @@ -445,7 +446,7 @@ export default class JobsAPI {
}

makeJobResponse(job, full = true) {
var response = {
const response = {
id: job._id,
title: job.title,
description: job.description,
Expand Down
15 changes: 8 additions & 7 deletions src/api/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class ServicesAPI {
};
const db = this.storage.database();
const service = await db.findOneAsync(query);
if (service === null) {
if (service === null) {
throw new Errors.ServiceNotFound();
}

Expand All @@ -48,7 +48,7 @@ export default class ServicesAPI {

const logs = await this.storage.getLogsById(req.params.service_id, service.log_level);

var pg = new ProcessGraph(service.process, context);
const pg = new ProcessGraph(service.process, context);
pg.setLogger(logs);
logger = logs;

Expand Down Expand Up @@ -124,15 +124,16 @@ export default class ServicesAPI {

const data = {};
const promises = [];
for(let key in req.body) {
for(const key in req.body) {
if (this.storage.isFieldEditable(key)) {
switch(key) {
case 'process':
var pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
case 'process': {
const pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
// ToDo 1.0: Correctly handle service paramaters #79
pg.allowUndefinedParameters(false);
promises.push(pg.validate());
break;
}
case 'type':
promises.push(async () => {
if (!this.context.isValidServiceType(req.body.type)) {
Expand Down Expand Up @@ -197,7 +198,7 @@ export default class ServicesAPI {
throw new Errors.ServiceUnsupported();
}

var pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
const pg = new ProcessGraph(req.body.process, this.context.processingContext(req));
// ToDo 1.0: Correctly handle service paramaters #79
pg.allowUndefinedParameters(false);
await pg.validate();
Expand Down Expand Up @@ -237,7 +238,7 @@ export default class ServicesAPI {
}

makeServiceResponse(service, full = true) {
var response = {
const response = {
id: service._id,
title: service.title || null,
description: service.description || null,
Expand Down
10 changes: 5 additions & 5 deletions src/api/storedprocessgraphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ export default class StoredProcessGraphs {
}

makeResponse(pg, full = true) {
var response = {
const response = {
id: pg.id
};
let optionalFields = ['summary', 'description', 'categories', 'parameters', 'returns', 'deprecated', 'experimental'];
for(let field of optionalFields) {
const optionalFields = ['summary', 'description', 'categories', 'parameters', 'returns', 'deprecated', 'experimental'];
for(const field of optionalFields) {
if (typeof pg[field] !== 'undefined') {
response[field] = pg[field];
}
}
if (full) {
let fullFields = ['exceptions', 'examples', 'links', 'process_graph'];
for(let field of fullFields) {
const fullFields = ['exceptions', 'examples', 'links', 'process_graph'];
for(const field of fullFields) {
if (typeof pg[field] !== 'undefined') {
response[field] = pg[field];
}
Expand Down
11 changes: 5 additions & 6 deletions src/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class UsersAPI {
}

async checkRequestAuthToken(req, res) {
var token = null;
let token = null;
if (req.authorization.scheme === 'Bearer') {
token = req.authorization.credentials;
}
Expand All @@ -26,8 +26,7 @@ export default class UsersAPI {
}

try {
const user = await this.storage.checkAuthToken(token);
req.user = user;
req.user = await this.storage.checkAuthToken(token);
} catch(err) {
res.send(Error.wrap(err));
}
Expand All @@ -41,7 +40,7 @@ export default class UsersAPI {
if (!req.authorization.scheme) {
throw new Errors.AuthenticationRequired();
}
else if (req.authorization.scheme != 'Basic') {
else if (req.authorization.scheme !== 'Basic') {
throw new Errors.AuthenticationSchemeInvalid();
}

Expand All @@ -57,7 +56,7 @@ export default class UsersAPI {
if (!req.user._id) {
throw new Errors.AuthenticationRequired();
}
var data = {
const data = {
user_id: req.user._id,
name: req.user.name,
budget: null,
Expand All @@ -81,7 +80,7 @@ export default class UsersAPI {
};
if (this.context.diskUsagePath !== null) {
try {
var info = await checkDiskSpace(this.context.diskUsagePath);
const info = await checkDiskSpace(this.context.diskUsagePath);
data.storage = {
free: info.free,
quota: info.size
Expand Down
Loading

0 comments on commit 8628422

Please sign in to comment.