Skip to content

Commit

Permalink
linting and adding eslint for pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
catsmith committed Mar 15, 2024
1 parent cfba568 commit 387711f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 59 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* global module */
module.exports = {
"plugins": [
'@stylistic'
],
"rules": {
"semi": "error",
"prefer-const": "warn",
"no-mixed-spaces-and-tabs": "off",
"@stylistic/no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
},
"env": {
"browser": true,
"es2021": true,
"jquery": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "script"
},
};
91 changes: 32 additions & 59 deletions static/api/js/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*jshint esversion: 6 */
var testing;
/* exported api */
var api = (function (){
"use strict";

// Private functions
var csrfSafeMethod, getEtag, setEtag, getCSRFToken;
Expand All @@ -27,9 +25,9 @@ var api = (function (){
} else {
etags = {};
}
if (etags.hasOwnProperty(app) &&
etags[app].hasOwnProperty(model) &&
etags[app][model].hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(etags, app) &&
Object.prototype.hasOwnProperty.call(etags[app], model) &&
Object.prototype.hasOwnProperty.call(etags[app][model], id)) {
return etags[app][model][id];
}
return '*';
Expand All @@ -45,10 +43,10 @@ var api = (function (){
etags = {};
}
if (etag !== null && etag !== undefined) {
if (!etags.hasOwnProperty(app)) {
if (!Object.prototype.hasOwnProperty.call(etags, app)) {
etags[app] = {};
}
if (!etags[app].hasOwnProperty(model)) {
if (!Object.prototype.hasOwnProperty.call(etags[app], model)) {
etags[app][model] = {};
}
etags[app][model][id] = '"' + etag + '"';
Expand Down Expand Up @@ -85,7 +83,7 @@ var api = (function (){
getCurrentUser = function (success_callback, error_callback) {
$.ajax({'url': '/api/whoami',
'method': 'GET'}
).done(function (response, textStatus, jqXHR) {
).done(function (response) {
if (typeof success_callback !== 'undefined') {
success_callback(response);
}
Expand Down Expand Up @@ -167,7 +165,7 @@ var api = (function (){

// TODO: consider whether this should also set etag for all items returned
getItemsFromDatabasePromise = function (app, model, criteria, method) {
if (typeof method === undefined) {
if (method === undefined) {
method = 'GET';
}
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -335,7 +333,7 @@ var api = (function (){
'dataType': 'json',
'method': 'PATCH'
}
).done(function (response) {//{'json': JSON.stringify(data), 'csrfmiddlewaretoken': csrf_token}, 'success': function (response) {
).done(function (response) {
if (typeof success_callback !== 'undefined') {
success_callback(response);
}
Expand All @@ -350,7 +348,7 @@ var api = (function (){
deleteM2MItemFromDatabasePromise = function (app, model, model_id, field_name, item_model, item_id) {
return new Promise(function (resolve, reject) {
$.ajax({'url': '/api/' + app + '/' + model + '/' + model_id + '/' + field_name + '/delete/' + item_model + '/' + item_id,
'headers': {'Content-Type': 'application/json'}, //'X-CSRFToken': csrf_token,
'headers': {'Content-Type': 'application/json'},
'dataType': 'json',
'method': 'PATCH'
}
Expand All @@ -362,52 +360,27 @@ var api = (function (){
});
};

if (testing) {
return {
// private
csrfSafeMethod: csrfSafeMethod,
getEtag: getEtag,
setEtag: setEtag,
// public
setupAjax: setupAjax,
createItemInDatabase: createItemInDatabase,
updateItemInDatabase: updateItemInDatabase,
updateFieldsInDatabase: updateFieldsInDatabase,
getItemFromDatabase: getItemFromDatabase,
getItemsFromDatabase: getItemsFromDatabase,
deleteItemFromDatabase: deleteItemFromDatabase,
deleteM2MItemFromDatabase: deleteM2MItemFromDatabase,
createItemInDatabasePromise: createItemInDatabasePromise,
updateItemInDatabasePromise: updateItemInDatabasePromise,
updateFieldsInDatabasePromise: updateFieldsInDatabasePromise,
getItemFromDatabasePromise: getItemFromDatabasePromise,
getItemsFromDatabasePromise: getItemsFromDatabasePromise,
deleteItemFromDatabasePromise: deleteItemFromDatabasePromise,
deleteM2MItemFromDatabasePromise: deleteM2MItemFromDatabasePromise,
getCurrentUserPromise: getCurrentUserPromise,
getCurrentUser: getCurrentUser
};
} else {
return {
setupAjax: setupAjax,
createItemInDatabase: createItemInDatabase,
updateItemInDatabase: updateItemInDatabase,
updateFieldsInDatabase: updateFieldsInDatabase,
getItemFromDatabase: getItemFromDatabase,
getItemsFromDatabase: getItemsFromDatabase,
deleteItemFromDatabase: deleteItemFromDatabase,
deleteM2MItemFromDatabase: deleteM2MItemFromDatabase,
createItemInDatabasePromise: createItemInDatabasePromise,
updateItemInDatabasePromise: updateItemInDatabasePromise,
updateFieldsInDatabasePromise: updateFieldsInDatabasePromise,
getItemFromDatabasePromise: getItemFromDatabasePromise,
getItemsFromDatabasePromise: getItemsFromDatabasePromise,
deleteItemFromDatabasePromise: deleteItemFromDatabasePromise,
deleteM2MItemFromDatabasePromise: deleteM2MItemFromDatabasePromise,
getCurrentUserPromise: getCurrentUserPromise,
getCurrentUser: getCurrentUser,
getCSRFToken: getCSRFToken
};
}

return {
setupAjax: setupAjax,
createItemInDatabase: createItemInDatabase,
updateItemInDatabase: updateItemInDatabase,
updateFieldsInDatabase: updateFieldsInDatabase,
getItemFromDatabase: getItemFromDatabase,
getItemsFromDatabase: getItemsFromDatabase,
deleteItemFromDatabase: deleteItemFromDatabase,
deleteM2MItemFromDatabase: deleteM2MItemFromDatabase,
createItemInDatabasePromise: createItemInDatabasePromise,
updateItemInDatabasePromise: updateItemInDatabasePromise,
updateFieldsInDatabasePromise: updateFieldsInDatabasePromise,
getItemFromDatabasePromise: getItemFromDatabasePromise,
getItemsFromDatabasePromise: getItemsFromDatabasePromise,
deleteItemFromDatabasePromise: deleteItemFromDatabasePromise,
deleteM2MItemFromDatabasePromise: deleteM2MItemFromDatabasePromise,
getCurrentUserPromise: getCurrentUserPromise,
getCurrentUser: getCurrentUser,
getCSRFToken: getCSRFToken
};


} () );

0 comments on commit 387711f

Please sign in to comment.