From 8cf13977a16253133dfab1663995a520e650491b Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 29 Nov 2023 15:14:53 +0100 Subject: [PATCH] DEV: Fix or disable various lint rules (#24630) A grab bag of smaller issues (constructor-super, no-fallthrough, ember/no-private-routing-service, no-unreachable, no-async-promise-executor) --- .../admin/addon/mixins/period-computation.js | 6 +-- .../lib/widget-hbs-compiler.js | 8 +--- .../app/components/composer-action-title.js | 35 +++++++-------- .../components/sidebar/section-link-prefix.js | 1 - .../component-templates.js | 1 + .../app/lib/homepage-router-overrides.js | 1 + .../discourse/app/models/category-list.js | 43 ++++++++----------- .../app/services/media-optimization-worker.js | 1 + .../topic-post-decorate-cooked-test.js | 2 +- 9 files changed, 43 insertions(+), 55 deletions(-) diff --git a/app/assets/javascripts/admin/addon/mixins/period-computation.js b/app/assets/javascripts/admin/addon/mixins/period-computation.js index 76ea98e06cb..a46b8c44cc1 100644 --- a/app/assets/javascripts/admin/addon/mixins/period-computation.js +++ b/app/assets/javascripts/admin/addon/mixins/period-computation.js @@ -14,21 +14,17 @@ export default Mixin.create({ @discourseComputed("period") startDate(period) { - let fullDay = moment().locale("en").utc().endOf("day"); + const fullDay = moment().locale("en").utc().endOf("day"); switch (period) { case "yearly": return fullDay.subtract(1, "year").startOf("day"); - break; case "quarterly": return fullDay.subtract(3, "month").startOf("day"); - break; case "weekly": return fullDay.subtract(6, "days").startOf("day"); - break; case "monthly": return fullDay.subtract(1, "month").startOf("day"); - break; default: return fullDay.subtract(1, "month").startOf("day"); } diff --git a/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js b/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js index 9477da921ca..0b5ac02826f 100644 --- a/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js +++ b/app/assets/javascripts/discourse-widget-hbs/lib/widget-hbs-compiler.js @@ -98,13 +98,10 @@ function mustacheValue(node, state) { opts ? argValue(opts) : opts }, ${otherOpts ? argValue(otherOpts) : otherOpts})`; - break; case "yield": return `this.attrs.contents()`; - break; case "i18n": return i18n(node); - break; case "avatar": let template = argValue( node.hash.pairs.find((p) => p.key === "template") @@ -117,13 +114,10 @@ function mustacheValue(node, state) { state, "avatar" )}(${size}, { template: ${template}, username: ${username} })`; - break; case "date": return `${useHelper(state, "dateNode")}(${valueOf(node.params[0])})`; - break; case "d-icon": return `${useHelper(state, "iconNode")}(${valueOf(node.params[0])})`; - break; default: // Shortcut: If our mustache has hash arguments, we can assume it's attaching. // For example `{{home-logo count=123}}` can become `this.attach('home-logo, { "count": 123 });` @@ -146,7 +140,6 @@ function mustacheValue(node, state) { path )} + ''})`; } - break; } } @@ -232,6 +225,7 @@ class Compiler { switch (node.path.original) { case "unless": negate = "!"; + // eslint-disable-next-line no-fallthrough case "if": instructions.push( `if (${negate}${resolve(node.params[0].original)}) {` diff --git a/app/assets/javascripts/discourse/app/components/composer-action-title.js b/app/assets/javascripts/discourse/app/components/composer-action-title.js index 09e78efc4ab..84590d2ecac 100644 --- a/app/assets/javascripts/discourse/app/components/composer-action-title.js +++ b/app/assets/javascripts/discourse/app/components/composer-action-title.js @@ -30,7 +30,7 @@ export default Component.extend({ // text customizations to use those. @discourseComputed("options", "action", "model.tags", "model.category") actionTitle(opts, action) { - let result = this.model.customizationFor("actionTitle"); + const result = this.model.customizationFor("actionTitle"); if (result) { return result; } @@ -39,22 +39,23 @@ export default Component.extend({ return I18n.t(TITLES[action]); } - switch (action) { - case REPLY: - if (opts.userAvatar && opts.userLink) { - return this._formatReplyToUserPost(opts.userAvatar, opts.userLink); - } else if (opts.topicLink) { - return this._formatReplyToTopic(opts.topicLink); - } - case EDIT: - if (opts.userAvatar && opts.userLink && opts.postLink) { - return this._formatEditUserPost( - opts.userAvatar, - opts.userLink, - opts.postLink, - opts.originalUser - ); - } + if (action === REPLY) { + if (opts.userAvatar && opts.userLink) { + return this._formatReplyToUserPost(opts.userAvatar, opts.userLink); + } else if (opts.topicLink) { + return this._formatReplyToTopic(opts.topicLink); + } + } + + if (action === EDIT) { + if (opts.userAvatar && opts.userLink && opts.postLink) { + return this._formatEditUserPost( + opts.userAvatar, + opts.userLink, + opts.postLink, + opts.originalUser + ); + } } }, diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section-link-prefix.js b/app/assets/javascripts/discourse/app/components/sidebar/section-link-prefix.js index 31ecf39dfb3..393cef5a852 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/section-link-prefix.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/section-link-prefix.js @@ -26,7 +26,6 @@ export default class extends Component { } return hexValues.join(", "); - break; default: return this.args.prefixValue; } diff --git a/app/assets/javascripts/discourse/app/instance-initializers/component-templates.js b/app/assets/javascripts/discourse/app/instance-initializers/component-templates.js index f460cf462f8..0dae7f9c25d 100644 --- a/app/assets/javascripts/discourse/app/instance-initializers/component-templates.js +++ b/app/assets/javascripts/discourse/app/instance-initializers/component-templates.js @@ -15,6 +15,7 @@ export function overrideThrowGjsError(value) { // This patch is not ideal, but Ember does not allow us to change a component template after initial association // https://github.com/glimmerjs/glimmer-vm/blob/03a4b55c03/packages/%40glimmer/manager/lib/public/template.ts#L14-L20 const originalGetTemplate = GlimmerManager.getComponentTemplate; +// eslint-disable-next-line no-import-assign GlimmerManager.getComponentTemplate = (component) => { return ( COLOCATED_TEMPLATE_OVERRIDES.get(component) ?? diff --git a/app/assets/javascripts/discourse/app/lib/homepage-router-overrides.js b/app/assets/javascripts/discourse/app/lib/homepage-router-overrides.js index 6ce4409a14b..7e5db91c3bb 100644 --- a/app/assets/javascripts/discourse/app/lib/homepage-router-overrides.js +++ b/app/assets/javascripts/discourse/app/lib/homepage-router-overrides.js @@ -9,6 +9,7 @@ import { defaultHomepage } from "discourse/lib/utilities"; * When detected, we rewrite the URL to `/` before saving it to the Ember router and the browser. */ export default function applyRouterHomepageOverrides(router) { + // eslint-disable-next-line ember/no-private-routing-service const microLib = router._routerMicrolib; for (const method of ["updateURL", "replaceURL"]) { diff --git a/app/assets/javascripts/discourse/app/models/category-list.js b/app/assets/javascripts/discourse/app/models/category-list.js index c018d2f340d..68eb5c35cd9 100644 --- a/app/assets/javascripts/discourse/app/models/category-list.js +++ b/app/assets/javascripts/discourse/app/models/category-list.js @@ -59,33 +59,28 @@ CategoryList.reopenClass({ c.topics = c.topics.map((t) => Topic.create(t)); } - switch (statPeriod) { - case "week": - case "month": - const stat = c[`topics_${statPeriod}`]; - if (stat > 0) { - const unit = I18n.t(`categories.topic_stat_unit.${statPeriod}`); + const stat = c[`topics_${statPeriod}`]; - c.stat = I18n.t("categories.topic_stat", { - count: stat, // only used to correctly pluralize the string - number: `${number(stat)}`, - unit: `${unit}`, - }); + if ((statPeriod === "week" || statPeriod === "month") && stat > 0) { + const unit = I18n.t(`categories.topic_stat_unit.${statPeriod}`); - c.statTitle = I18n.t(`categories.topic_stat_sentence_${statPeriod}`, { - count: stat, - }); + c.stat = I18n.t("categories.topic_stat", { + count: stat, // only used to correctly pluralize the string + number: `${number(stat)}`, + unit: `${unit}`, + }); - c.pickAll = false; - break; - } - default: - c.stat = `${number(c.topics_all_time)}`; - c.statTitle = I18n.t("categories.topic_sentence", { - count: c.topics_all_time, - }); - c.pickAll = true; - break; + c.statTitle = I18n.t(`categories.topic_stat_sentence_${statPeriod}`, { + count: stat, + }); + + c.pickAll = false; + } else { + c.stat = `${number(c.topics_all_time)}`; + c.statTitle = I18n.t("categories.topic_sentence", { + count: c.topics_all_time, + }); + c.pickAll = true; } if (Site.currentProp("mobileView")) { diff --git a/app/assets/javascripts/discourse/app/services/media-optimization-worker.js b/app/assets/javascripts/discourse/app/services/media-optimization-worker.js index 57c4bb22065..ee5ac840a91 100644 --- a/app/assets/javascripts/discourse/app/services/media-optimization-worker.js +++ b/app/assets/javascripts/discourse/app/services/media-optimization-worker.js @@ -53,6 +53,7 @@ export default class MediaOptimizationWorkerService extends Service { } await this.ensureAvailableWorker(); + // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve) => { this.logIfDebug(`Transforming ${file.name}`); diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-post-decorate-cooked-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-post-decorate-cooked-test.js index 78ca9fe28bd..86acd205e70 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-post-decorate-cooked-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-post-decorate-cooked-test.js @@ -12,7 +12,7 @@ acceptance("Acceptance | decorateCookedElement", function () { static eventLog = []; constructor() { DemoComponent.eventLog.push("created"); - return super(...arguments); + super(...arguments); } willDestroy() { super.willDestroy(...arguments);