Merge pull request #10552 from akx/eslint-moar

More Eslint fixes
This commit is contained in:
AUTOMATIC1111 2023-05-19 16:34:27 +03:00 committed by GitHub
commit d41a31a508
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 71 deletions

View File

@ -1,3 +1,4 @@
/* global module */
module.exports = { module.exports = {
env: { env: {
browser: true, browser: true,
@ -25,9 +26,14 @@ module.exports = {
"linebreak-style": ["error", "unix"], "linebreak-style": ["error", "unix"],
"no-extra-semi": "error", "no-extra-semi": "error",
"no-mixed-spaces-and-tabs": "error", "no-mixed-spaces-and-tabs": "error",
"no-multi-spaces": "error",
"no-redeclare": ["error", {builtinGlobals: false}],
"no-trailing-spaces": "error", "no-trailing-spaces": "error",
"no-unused-vars": "off",
"no-whitespace-before-property": "error", "no-whitespace-before-property": "error",
"object-curly-newline": ["error", {consistent: true, multiline: true}], "object-curly-newline": ["error", {consistent: true, multiline: true}],
"object-curly-spacing": ["error", "never"],
"operator-linebreak": ["error", "after"],
"quote-props": ["error", "consistent-as-needed"], "quote-props": ["error", "consistent-as-needed"],
"semi": ["error", "always"], "semi": ["error", "always"],
"semi-spacing": "error", "semi-spacing": "error",
@ -40,51 +46,43 @@ module.exports = {
"switch-colon-spacing": "error", "switch-colon-spacing": "error",
"template-curly-spacing": ["error", "never"], "template-curly-spacing": ["error", "never"],
"unicode-bom": "error", "unicode-bom": "error",
"no-multi-spaces": "error",
"object-curly-spacing": ["error", "never"],
"operator-linebreak": ["error", "after"],
"no-unused-vars": "off",
"no-redeclare": "off",
}, },
globals: { globals: {
// this file
module: "writable",
//script.js //script.js
gradioApp: "writable", gradioApp: "readonly",
onUiLoaded: "writable", onUiLoaded: "readonly",
onUiUpdate: "writable", onUiUpdate: "readonly",
onOptionsChanged: "writable", onOptionsChanged: "readonly",
uiCurrentTab: "writable", uiCurrentTab: "writable",
uiElementIsVisible: "writable", uiElementIsVisible: "readonly",
uiElementInSight: "writable", uiElementInSight: "readonly",
executeCallbacks: "writable", executeCallbacks: "readonly",
//ui.js //ui.js
opts: "writable", opts: "writable",
all_gallery_buttons: "writable", all_gallery_buttons: "readonly",
selected_gallery_button: "writable", selected_gallery_button: "readonly",
selected_gallery_index: "writable", selected_gallery_index: "readonly",
args_to_array: "writable", switch_to_txt2img: "readonly",
switch_to_txt2img: "writable", switch_to_img2img_tab: "readonly",
switch_to_img2img_tab: "writable", switch_to_img2img: "readonly",
switch_to_img2img: "writable", switch_to_sketch: "readonly",
switch_to_sketch: "writable", switch_to_inpaint: "readonly",
switch_to_inpaint: "writable", switch_to_inpaint_sketch: "readonly",
switch_to_inpaint_sketch: "writable", switch_to_extras: "readonly",
switch_to_extras: "writable", get_tab_index: "readonly",
get_tab_index: "writable", create_submit_args: "readonly",
create_submit_args: "writable", restart_reload: "readonly",
restart_reload: "writable", updateInput: "readonly",
updateInput: "writable",
//extraNetworks.js //extraNetworks.js
requestGet: "writable", requestGet: "readonly",
popup: "writable", popup: "readonly",
// from python // from python
localization: "writable", localization: "readonly",
// progrssbar.js // progrssbar.js
randomId: "writable", randomId: "readonly",
requestProgress: "writable", requestProgress: "readonly",
// imageviewer.js // imageviewer.js
modalPrevImage: "writable", modalPrevImage: "readonly",
modalNextImage: "writable", modalNextImage: "readonly",
} }
}; };

View File

@ -9,7 +9,7 @@ function start_training_textual_inversion() {
gradioApp().getElementById('ti_progress').innerHTML = progress.textinfo; gradioApp().getElementById('ti_progress').innerHTML = progress.textinfo;
}); });
var res = args_to_array(arguments); var res = Array.from(arguments);
res[0] = id; res[0] = id;

View File

@ -61,18 +61,12 @@ function extract_image_from_gallery(gallery) {
return [gallery[index]]; return [gallery[index]];
} }
function args_to_array(args) { window.args_to_array = Array.from; // Compatibility with e.g. extensions that may expect this to be around
var res = [];
for (var i = 0; i < args.length; i++) {
res.push(args[i]);
}
return res;
}
function switch_to_txt2img() { function switch_to_txt2img() {
gradioApp().querySelector('#tabs').querySelectorAll('button')[0].click(); gradioApp().querySelector('#tabs').querySelectorAll('button')[0].click();
return args_to_array(arguments); return Array.from(arguments);
} }
function switch_to_img2img_tab(no) { function switch_to_img2img_tab(no) {
@ -81,65 +75,55 @@ function switch_to_img2img_tab(no) {
} }
function switch_to_img2img() { function switch_to_img2img() {
switch_to_img2img_tab(0); switch_to_img2img_tab(0);
return args_to_array(arguments); return Array.from(arguments);
} }
function switch_to_sketch() { function switch_to_sketch() {
switch_to_img2img_tab(1); switch_to_img2img_tab(1);
return args_to_array(arguments); return Array.from(arguments);
} }
function switch_to_inpaint() { function switch_to_inpaint() {
switch_to_img2img_tab(2); switch_to_img2img_tab(2);
return args_to_array(arguments); return Array.from(arguments);
} }
function switch_to_inpaint_sketch() { function switch_to_inpaint_sketch() {
switch_to_img2img_tab(3); switch_to_img2img_tab(3);
return args_to_array(arguments); return Array.from(arguments);
} }
function switch_to_extras() { function switch_to_extras() {
gradioApp().querySelector('#tabs').querySelectorAll('button')[2].click(); gradioApp().querySelector('#tabs').querySelectorAll('button')[2].click();
return args_to_array(arguments); return Array.from(arguments);
} }
function get_tab_index(tabId) { function get_tab_index(tabId) {
var res = 0; let buttons = gradioApp().getElementById(tabId).querySelector('div').querySelectorAll('button');
for (let i = 0; i < buttons.length; i++) {
gradioApp().getElementById(tabId).querySelector('div').querySelectorAll('button').forEach(function(button, i) { if (buttons[i].classList.contains('selected')) {
if (button.className.indexOf('selected') != -1) { return i;
res = i;
} }
}); }
return 0;
return res;
} }
function create_tab_index_args(tabId, args) { function create_tab_index_args(tabId, args) {
var res = []; var res = Array.from(args);
for (var i = 0; i < args.length; i++) {
res.push(args[i]);
}
res[0] = get_tab_index(tabId); res[0] = get_tab_index(tabId);
return res; return res;
} }
function get_img2img_tab_index() { function get_img2img_tab_index() {
let res = args_to_array(arguments); let res = Array.from(arguments);
res.splice(-2); res.splice(-2);
res[0] = get_tab_index('mode_img2img'); res[0] = get_tab_index('mode_img2img');
return res; return res;
} }
function create_submit_args(args) { function create_submit_args(args) {
var res = []; var res = Array.from(args);
for (var i = 0; i < args.length; i++) {
res.push(args[i]);
}
// As it is currently, txt2img and img2img send back the previous output args (txt2img_gallery, generation_info, html_info) whenever you generate a new image. // As it is currently, txt2img and img2img send back the previous output args (txt2img_gallery, generation_info, html_info) whenever you generate a new image.
// This can lead to uploading a huge gallery of previously generated images, which leads to an unnecessary delay between submitting and beginning to generate. // This can lead to uploading a huge gallery of previously generated images, which leads to an unnecessary delay between submitting and beginning to generate.
@ -275,13 +259,13 @@ function recalculatePromptTokens(name) {
function recalculate_prompts_txt2img() { function recalculate_prompts_txt2img() {
recalculatePromptTokens('txt2img_prompt'); recalculatePromptTokens('txt2img_prompt');
recalculatePromptTokens('txt2img_neg_prompt'); recalculatePromptTokens('txt2img_neg_prompt');
return args_to_array(arguments); return Array.from(arguments);
} }
function recalculate_prompts_img2img() { function recalculate_prompts_img2img() {
recalculatePromptTokens('img2img_prompt'); recalculatePromptTokens('img2img_prompt');
recalculatePromptTokens('img2img_neg_prompt'); recalculatePromptTokens('img2img_neg_prompt');
return args_to_array(arguments); return Array.from(arguments);
} }