Skip to content

Commit

Permalink
fix: All ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Jul 14, 2023
1 parent 9d357f3 commit 58cf770
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"indent": "off",
"brace-style": "off",
"no-mixed-spaces-and-tabs": "off",
"no-useless-escape": "off",
"space-unary-ops": ["error", { "words": true }],
"linebreak-style": "off",
"quotes": ["off"],
Expand All @@ -21,15 +22,12 @@
"no-console": ["warn"],
"no-extra-boolean-cast": ["off"],
"no-control-regex": ["off"],
"space-before-blocks": "warn",
"keyword-spacing": "warn",
"comma-spacing": "warn",
"key-spacing": "warn"
},
"root": true,
"globals": {
"frappe": true,
"Vue": true,
"SetVueGlobals": true,
"__": true,
"repl": true,
"Class": true,
Expand All @@ -45,8 +43,10 @@
"is_null": true,
"in_list": true,
"has_common": true,
"posthog": true,
"has_words": true,
"validate_email": true,
"open_web_template_values_editor": true,
"validate_name": true,
"validate_phone": true,
"validate_url": true,
Expand Down
4 changes: 2 additions & 2 deletions frappe/core/doctype/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ frappe.ui.form.on("User", {

if (frappe.route_flags.unsaved === 1) {
delete frappe.route_flags.unsaved;
for (var i = 0; i < frm.doc.user_emails.length; i++) {
for (let i = 0; i < frm.doc.user_emails.length; i++) {
frm.doc.user_emails[i].idx = frm.doc.user_emails[i].idx + 1;
}
frm.dirty();
Expand Down Expand Up @@ -308,7 +308,7 @@ frappe.ui.form.on("User", {
enable_incoming: 1,
};
frappe.model.with_doctype("Email Account", function (doc) {
var doc = frappe.model.get_new_doc("Email Account");
doc = frappe.model.get_new_doc("Email Account");
frappe.route_flags.linked_user = frm.doc.name;
frappe.route_flags.delete_user_from_locals = true;
frappe.set_route("Form", "Email Account", doc.name);
Expand Down
2 changes: 1 addition & 1 deletion frappe/custom/doctype/doctype_layout/doctype_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ frappe.ui.form.on("DocType Layout", {
await frm.events.sync_fields(frm, false);

if (frm.is_new()) {
frm.doc.__newname = document_name;
frm.doc.__newname = document_name; // eslint-disable-line
frm.refresh_field("__newname");
}
}
Expand Down
2 changes: 1 addition & 1 deletion frappe/desk/page/setup_wizard/setup_wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ function guess_country(country_info) {
try {
const system_timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;

for ([country, info] of Object.entries(country_info)) {
for (let [country, info] of Object.entries(country_info)) {
let possible_timezones = (info.timezones || []).filter((t) => t == system_timezone);
if (possible_timezones.length) return country;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,11 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder {
if (!$item.hasClass("print-format-builder-field")) {
var fieldname = $item.attr("data-fieldname");

let field;
if (fieldname === "_custom_html") {
var field = me.get_custom_html_field();
field = me.get_custom_html_field();
} else {
var field = frappe.meta.get_docfield(me.print_format.doc_type, fieldname);
field = frappe.meta.get_docfield(me.print_format.doc_type, fieldname);
}

var html = frappe.render_template("print_format_builder_field", {
Expand Down Expand Up @@ -561,7 +562,7 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder {
resize();
} else if (new_no_of_columns > no_of_columns) {
// add empty column and resize old columns
for (var i = no_of_columns; i < new_no_of_columns; i++) {
for (let i = no_of_columns; i < new_no_of_columns; i++) {
var col = $(
'<div class="section-column">\
<div class="print-format-builder-column"></div></div>'
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ frappe.defaults = {
if (!d && frappe.defaults.is_a_user_permission_key(key)) {
d = defaults[frappe.model.scrub(key)];
// Check for default user permission values
user_default = this.get_user_permission_default(key, defaults);
let user_default = this.get_user_permission_default(key, defaults);
if (user_default) d = user_default;
}
if ($.isArray(d)) d = d[0];
Expand Down
5 changes: 3 additions & 2 deletions frappe/public/js/frappe/form/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,13 @@ export default class Grid {
if (d.name === undefined) {
d.name = "row " + d.idx;
}
let grid_row;
if (this.grid_rows[ri] && !append_row) {
var grid_row = this.grid_rows[ri];
grid_row = this.grid_rows[ri];
grid_row.doc = d;
grid_row.refresh();
} else {
var grid_row = new GridRow({
grid_row = new GridRow({
parent: $rows,
parent_df: this.df,
docfields: this.docfields,
Expand Down
5 changes: 3 additions & 2 deletions frappe/public/js/frappe/form/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,20 @@ frappe.ui.form.save = function (frm, action, callback, btn) {

if (error_fields.length) {
let meta = frappe.get_meta(doc.doctype);
let message;
if (meta.istable) {
const table_field = frappe.meta.docfield_map[doc.parenttype][doc.parentfield];

const table_label = __(
table_field.label || frappe.unscrub(table_field.fieldname)
).bold();

var message = __("Mandatory fields required in table {0}, Row {1}", [
message = __("Mandatory fields required in table {0}, Row {1}", [
table_label,
doc.idx,
]);
} else {
var message = __("Mandatory fields required in {0}", [__(doc.doctype)]);
message = __("Mandatory fields required in {0}", [__(doc.doctype)]);
}
message = message + "<br><br><ul><li>" + error_fields.join("</li><li>") + "</ul>";
frappe.msgprint({
Expand Down
7 changes: 4 additions & 3 deletions frappe/public/js/frappe/form/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ frappe.ui.form.Toolbar = class Toolbar {
}
}
set_title() {
let title;
if (this.frm.is_new()) {
var title = __("New {0}", [__(this.frm.meta.name)]);
title = __("New {0}", [__(this.frm.meta.name)]);
} else if (this.frm.meta.title_field) {
let title_field = (this.frm.doc[this.frm.meta.title_field] || "").toString().trim();
var title = strip_html(title_field || this.frm.docname);
title = strip_html(title_field || this.frm.docname);
if (
this.frm.doc.__islocal ||
title === this.frm.docname ||
Expand All @@ -51,7 +52,7 @@ frappe.ui.form.Toolbar = class Toolbar {
});
}
} else {
var title = this.frm.docname;
title = this.frm.docname;
}

var me = this;
Expand Down
9 changes: 7 additions & 2 deletions frappe/public/js/frappe/microtemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Adapted from John Resig - http://ejohn.org/ - MIT Licensed

frappe.template = { compiled: {}, debug: {} };

/* eslint-disable */
frappe.template.compile = function (str, name) {
var key = name || str;

Expand Down Expand Up @@ -96,14 +98,17 @@ frappe.template.compile = function (str, name) {

return frappe.template.compiled[key];
};
/* eslint-enable */

frappe.render = function (str, data, name) {
return frappe.template.compile(str, name)(data);
};
frappe.render_template = function (name, data) {
let template;
if (name.indexOf(" ") !== -1) {
var template = name;
template = name;
} else {
var template = frappe.templates[name];
template = frappe.templates[name];
}
if (data === undefined) {
data = {};
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/model/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ frappe.get_indicator = function (doc, doctype, show_workflow_state) {
if (workflow_fieldname && (!without_workflow || show_workflow_state)) {
var value = doc[workflow_fieldname];
if (value) {
var colour = "";
let colour = "";

if (locals["Workflow State"][value] && locals["Workflow State"][value].style) {
var colour = {
colour = {
Success: "green",
Warning: "orange",
Danger: "red",
Expand Down
18 changes: 10 additions & 8 deletions frappe/public/js/frappe/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,17 @@ $.extend(frappe.model, {
var val = locals[dt] && locals[dt][dn] && locals[dt][dn][fn];
var df = frappe.meta.get_docfield(dt, fn, dn);

let ret;
if (frappe.model.table_fields.includes(df.fieldtype)) {
var ret = false;
ret = false;
$.each(locals[df.options] || {}, function (k, d) {
if (d.parent == dn && d.parenttype == dt && d.parentfield == df.fieldname) {
ret = true;
return false;
}
});
} else {
var ret = !is_null(val);
ret = !is_null(val);
}
return ret ? true : false;
},
Expand Down Expand Up @@ -616,12 +617,13 @@ $.extend(frappe.model, {
},

get_children: function (doctype, parent, parentfield, filters) {
let doc;
if ($.isPlainObject(doctype)) {
var doc = doctype;
var filters = parentfield;
var parentfield = parent;
doc = doctype;
filters = parentfield;
parentfield = parent;
} else {
var doc = frappe.get_doc(doctype, parent);
doc = frappe.get_doc(doctype, parent);
}

var children = doc[parentfield] || [];
Expand Down Expand Up @@ -652,8 +654,8 @@ $.extend(frappe.model, {

var parent = null;
if (doc.parenttype) {
var parent = doc.parent,
parenttype = doc.parenttype,
parent = doc.parent;
var parenttype = doc.parenttype,
parentfield = doc.parentfield;
}
delete locals[doctype][name];
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ frappe.request.call = function (opts) {
data = JSON.parse(data);
}
if (data.responseText) {
var xhr = data;
var xhr = data; // eslint-disable-line
data = JSON.parse(data.responseText);
}
} catch (e) {
Expand Down
7 changes: 4 additions & 3 deletions frappe/public/js/frappe/ui/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ frappe.prompt = function (fields, callback, title, primary_label) {
frappe.msgprint = function (msg, title, is_minimizable) {
if (!msg) return;

let data;
if ($.isPlainObject(msg)) {
var data = msg;
data = msg;
} else {
// passed as JSON
if (typeof msg === "string" && msg.substr(0, 1) === "{") {
var data = JSON.parse(msg);
data = JSON.parse(msg);
} else {
var data = { message: msg, title: title };
data = { message: msg, title: title };
}
}

Expand Down
5 changes: 3 additions & 2 deletions frappe/public/js/frappe/ui/toolbar/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ frappe.ui.misc.about = function () {
var $wrap = $("#about-app-versions").empty();
$.each(Object.keys(versions).sort(), function (i, key) {
var v = versions[key];
let text;
if (v.branch) {
var text = $.format("<p><b>{0}:</b> v{1} ({2})<br></p>", [
text = $.format("<p><b>{0}:</b> v{1} ({2})<br></p>", [
v.title,
v.branch_version || v.version,
v.branch,
]);
} else {
var text = $.format("<p><b>{0}:</b> v{1}<br></p>", [v.title, v.version]);
text = $.format("<p><b>{0}:</b> v{1}<br></p>", [v.title, v.version]);
}
$(text).appendTo($wrap);
});
Expand Down
9 changes: 5 additions & 4 deletions frappe/public/js/frappe/ui/toolbar/search_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,13 @@ frappe.search.utils = {
var part = parts[i];
if (part.toLowerCase().indexOf(keywords) !== -1) {
// If the field contains the keyword
let colon_index, field_value;
if (part.indexOf(" &&& ") !== -1) {
var colon_index = part.indexOf(" &&& ");
var field_value = part.slice(colon_index + 5);
colon_index = part.indexOf(" &&& ");
field_value = part.slice(colon_index + 5);
} else {
var colon_index = part.indexOf(" : ");
var field_value = part.slice(colon_index + 3);
colon_index = part.indexOf(" : ");
field_value = part.slice(colon_index + 3);
}
if (field_value.length > field_length) {
// If field value exceeds field_length, find the keyword in it
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/ui/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ frappe.ui.toolbar.Toolbar = class {
var breadcrumbs = route.split("/");

var links = [];
for (var i = 0; i < breadcrumbs.length; i++) {
for (let i = 0; i < breadcrumbs.length; i++) {
var r = route.split("/", i + 1);
var key = r.join("/");
var help_links = frappe.help.help_links[key] || [];
Expand All @@ -95,7 +95,7 @@ frappe.ui.toolbar.Toolbar = class {
$help_links.next().show();
}

for (var i = 0; i < links.length; i++) {
for (let i = 0; i < links.length; i++) {
var link = links[i];
var url = link.url;
$("<a>", {
Expand Down
5 changes: 3 additions & 2 deletions frappe/public/js/frappe/utils/number_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ function in_list(list, item) {
function remainder(numerator, denominator, precision) {
precision = cint(precision);
var multiplier = Math.pow(10, precision);
let _remainder;
if (precision) {
var _remainder = ((numerator * multiplier) % (denominator * multiplier)) / multiplier;
_remainder = ((numerator * multiplier) % (denominator * multiplier)) / multiplier;
} else {
var _remainder = numerator % denominator;
_remainder = numerator % denominator;
}

return flt(_remainder, precision);
Expand Down
5 changes: 3 additions & 2 deletions frappe/public/js/frappe/utils/user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
frappe.user_info = function (uid) {
if (!uid) uid = frappe.session.user;

let user_info;
if (!(frappe.boot.user_info && frappe.boot.user_info[uid])) {
var user_info = { fullname: uid || "Unknown" };
user_info = { fullname: uid || "Unknown" };
} else {
var user_info = frappe.boot.user_info[uid];
user_info = frappe.boot.user_info[uid];
}

user_info.abbr = frappe.get_abbr(user_info.fullname);
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ Object.assign(frappe.utils, {
break;
case "url":
regExp =
/^((([A-Za-z0-9.+-]+:(?:\/\/)?)(?:[-;:&=\+\,\w]@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/i;
/^((([A-Za-z0-9.+-]+:(?:\/\/)?)(?:[-;:&=\+\,\w]@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/i; // eslint-disable-line
break;
case "dateIso":
regExp = /^(\d{4})\D?(0[1-9]|1[0-2])\D?([12]\d|0[1-9]|3[01])$/;
Expand Down
5 changes: 3 additions & 2 deletions frappe/public/js/frappe/views/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ frappe.views.Container = class Container {
}
change_to(label) {
cur_page = this;
let page;
if (label.tagName) {
// if sent the div, get the table
var page = label;
page = label;
} else {
var page = frappe.pages[label];
page = frappe.pages[label];
}
if (!page) {
console.log(__("Page not found") + ": " + label);
Expand Down
Loading

0 comments on commit 58cf770

Please sign in to comment.