From 9ca93f57cce1f9a9a7e482fd1c15b5e9af288fab Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 12 Nov 2021 19:23:20 +0100 Subject: [PATCH] DEV: Remove `jQuery` global usage where possible (#14905) --- .eslintrc | 1 + app/assets/javascripts/discourse/app/helpers/raw.js | 4 ++-- app/assets/javascripts/discourse/app/lib/formatter.js | 1 + app/assets/javascripts/discourse/app/lib/highlight-syntax.js | 1 + app/assets/javascripts/discourse/app/lib/link-hashtags.js | 1 + app/assets/javascripts/discourse/app/lib/link-mentions.js | 1 + app/assets/javascripts/discourse/app/lib/plugin-connectors.js | 2 +- .../javascripts/discourse/app/lib/timeframes-builder.js | 2 +- app/assets/javascripts/discourse/app/widgets/button.js | 2 +- app/assets/javascripts/discourse/app/widgets/header.js | 4 ++-- .../javascripts/discourse/app/widgets/post-admin-menu.js | 2 +- .../javascripts/discourse/tests/helpers/select-kit-helper.js | 1 + app/assets/javascripts/discourse/tests/setup-tests.js | 1 + app/assets/javascripts/wizard/components/wizard-step.js | 1 + 14 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8706c9f23d5..62dbb92b839 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,7 @@ "eol-last": 2 }, "globals": { + "jQuery": "off", "moduleFor": "off", "moduleForComponent": "off", "testStart": "off", diff --git a/app/assets/javascripts/discourse/app/helpers/raw.js b/app/assets/javascripts/discourse/app/helpers/raw.js index c9dd07f8b4f..0ad2d6edd51 100644 --- a/app/assets/javascripts/discourse/app/helpers/raw.js +++ b/app/assets/javascripts/discourse/app/helpers/raw.js @@ -18,7 +18,7 @@ function lookupView(templateName) { } function renderRaw(ctx, template, templateName, params) { - params = jQuery.extend({}, params); + params = Object.assign({}, params); params.parent = params.parent || ctx; let context = helperContext(); @@ -30,7 +30,7 @@ function renderRaw(ctx, template, templateName, params) { } if (!params.view) { - params = jQuery.extend({}, params, context); + params = Object.assign({}, params, context); } } diff --git a/app/assets/javascripts/discourse/app/lib/formatter.js b/app/assets/javascripts/discourse/app/lib/formatter.js index f2ad73796d3..90ddf88e1d8 100644 --- a/app/assets/javascripts/discourse/app/lib/formatter.js +++ b/app/assets/javascripts/discourse/app/lib/formatter.js @@ -50,6 +50,7 @@ export function longDateNoYear(dt) { } export function updateRelativeAge(elems) { + // eslint-disable-next-line no-undef if (elems instanceof jQuery) { elems = elems.toArray(); deprecated("updateRelativeAge now expects a DOM NodeList", { diff --git a/app/assets/javascripts/discourse/app/lib/highlight-syntax.js b/app/assets/javascripts/discourse/app/lib/highlight-syntax.js index 3a1a5d9b864..62e2a05f253 100644 --- a/app/assets/javascripts/discourse/app/lib/highlight-syntax.js +++ b/app/assets/javascripts/discourse/app/lib/highlight-syntax.js @@ -14,6 +14,7 @@ export default function highlightSyntax(elem, siteSettings, session) { : "pre code[class]"; const path = session.highlightJsPath; + // eslint-disable-next-line no-undef if (elem instanceof jQuery) { deprecated( "highlightSyntax now takes a DOM node instead of a jQuery object.", diff --git a/app/assets/javascripts/discourse/app/lib/link-hashtags.js b/app/assets/javascripts/discourse/app/lib/link-hashtags.js index 5a647d85039..7d1fa263208 100644 --- a/app/assets/javascripts/discourse/app/lib/link-hashtags.js +++ b/app/assets/javascripts/discourse/app/lib/link-hashtags.js @@ -8,6 +8,7 @@ const tagHashtags = {}; const checkedHashtags = new Set(); export function linkSeenHashtags(elem) { + // eslint-disable-next-line no-undef if (elem instanceof jQuery) { elem = elem[0]; diff --git a/app/assets/javascripts/discourse/app/lib/link-mentions.js b/app/assets/javascripts/discourse/app/lib/link-mentions.js index ab9aca48118..8abfc47e5b1 100644 --- a/app/assets/javascripts/discourse/app/lib/link-mentions.js +++ b/app/assets/javascripts/discourse/app/lib/link-mentions.js @@ -67,6 +67,7 @@ function updateFound(mentions, usernames) { } export function linkSeenMentions(elem, siteSettings) { + // eslint-disable-next-line no-undef if (elem instanceof jQuery) { elem = elem[0]; diff --git a/app/assets/javascripts/discourse/app/lib/plugin-connectors.js b/app/assets/javascripts/discourse/app/lib/plugin-connectors.js index 71d922e367e..83232ff07f8 100644 --- a/app/assets/javascripts/discourse/app/lib/plugin-connectors.js +++ b/app/assets/javascripts/discourse/app/lib/plugin-connectors.js @@ -53,7 +53,7 @@ function findClass(outletName, uniqueName) { let foundClass = _extraConnectorClasses[id] || _classPaths[id]; return foundClass - ? jQuery.extend({}, DefaultConnectorClass, foundClass) + ? Object.assign({}, DefaultConnectorClass, foundClass) : DefaultConnectorClass; } diff --git a/app/assets/javascripts/discourse/app/lib/timeframes-builder.js b/app/assets/javascripts/discourse/app/lib/timeframes-builder.js index 6fd51382092..cdfd0a3d2bd 100644 --- a/app/assets/javascripts/discourse/app/lib/timeframes-builder.js +++ b/app/assets/javascripts/discourse/app/lib/timeframes-builder.js @@ -6,7 +6,7 @@ const TIMEFRAME_BASE = { }; function buildTimeframe(opts) { - return jQuery.extend({}, TIMEFRAME_BASE, opts); + return Object.assign({}, TIMEFRAME_BASE, opts); } const TIMEFRAMES = [ diff --git a/app/assets/javascripts/discourse/app/widgets/button.js b/app/assets/javascripts/discourse/app/widgets/button.js index 29f071f7f8e..242736aec1c 100644 --- a/app/assets/javascripts/discourse/app/widgets/button.js +++ b/app/assets/javascripts/discourse/app/widgets/button.js @@ -131,7 +131,7 @@ export default createWidget("button", ButtonClass); createWidget( "flat-button", - jQuery.extend(ButtonClass, { + Object.assign(ButtonClass, { tagName: "button.widget-button.btn-flat", }) ); diff --git a/app/assets/javascripts/discourse/app/widgets/header.js b/app/assets/javascripts/discourse/app/widgets/header.js index 8adbe4d533c..68aab4d7c71 100644 --- a/app/assets/javascripts/discourse/app/widgets/header.js +++ b/app/assets/javascripts/discourse/app/widgets/header.js @@ -146,7 +146,7 @@ createWidget("header-notifications", { createWidget( "user-dropdown", - jQuery.extend( + Object.assign( { tagName: "li.header-dropdown-toggle.current-user", @@ -176,7 +176,7 @@ createWidget( createWidget( "header-dropdown", - jQuery.extend( + Object.assign( { tagName: "li.header-dropdown-toggle", diff --git a/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js b/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js index 7564ce2eb5e..6f3c271ad0d 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js +++ b/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js @@ -4,7 +4,7 @@ import { h } from "virtual-dom"; createWidget( "post-admin-menu-button", - jQuery.extend(ButtonClass, { tagName: "li.btn" }) + Object.assign(ButtonClass, { tagName: "li.btn" }) ); createWidget("post-admin-menu-button", { diff --git a/app/assets/javascripts/discourse/tests/helpers/select-kit-helper.js b/app/assets/javascripts/discourse/tests/helpers/select-kit-helper.js index e283466d673..4fb02bee758 100644 --- a/app/assets/javascripts/discourse/tests/helpers/select-kit-helper.js +++ b/app/assets/javascripts/discourse/tests/helpers/select-kit-helper.js @@ -65,6 +65,7 @@ async function keyboardHelper(value, target, selector) { if (value === "selectAll") { // special casing the only one not working with triggerEvent + // eslint-disable-next-line no-undef const event = jQuery.Event("keydown"); event.key = "A"; event.keyCode = 65; diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index de260e32267..32d909e9f9a 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -379,6 +379,7 @@ function setupTestsCommon(application, container, config) { } // forces 0 as duration for all jquery animations + // eslint-disable-next-line no-undef jQuery.fx.off = true; setupToolbar(); diff --git a/app/assets/javascripts/wizard/components/wizard-step.js b/app/assets/javascripts/wizard/components/wizard-step.js index 1d66e86cca9..48e3f758649 100644 --- a/app/assets/javascripts/wizard/components/wizard-step.js +++ b/app/assets/javascripts/wizard/components/wizard-step.js @@ -5,6 +5,7 @@ import getUrl from "discourse-common/lib/get-url"; import { htmlSafe } from "@ember/template"; import { schedule } from "@ember/runloop"; +// eslint-disable-next-line no-undef jQuery.fn.wiggle = function (times, duration) { if (times > 0) { this.animate(