DEV: Disallow Ember global usage (#16147)

…and sprinkle `// eslint-disable-next-line no-undef` throughout the code where is unavoidable for now
This commit is contained in:
Jarek Radosz 2022-03-09 17:54:07 +01:00 committed by GitHub
parent 2ba602708a
commit 99b2cfe26e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 58 additions and 6 deletions

View File

@ -16,6 +16,7 @@
"currentURL": "off", "currentURL": "off",
"currentUser": "off", "currentUser": "off",
"Discourse": "off", "Discourse": "off",
"Ember": "off",
"exists": "off", "exists": "off",
"fillIn": "off", "fillIn": "off",
"find": "off", "find": "off",

View File

@ -13,8 +13,10 @@
).__DISCOURSE_RAW_TEMPLATES; ).__DISCOURSE_RAW_TEMPLATES;
// required for addons to work without Ember CLI // required for addons to work without Ember CLI
// eslint-disable-next-line no-undef
Object.keys(Ember.TEMPLATES).forEach((k) => { Object.keys(Ember.TEMPLATES).forEach((k) => {
if (k.indexOf("select-kit") === 0) { if (k.indexOf("select-kit") === 0) {
// eslint-disable-next-line no-undef
let template = Ember.TEMPLATES[k]; let template = Ember.TEMPLATES[k];
define(k, () => template); define(k, () => template);
} }

View File

@ -11,10 +11,12 @@ export function setEnvironment(e) {
} }
export function isTesting() { export function isTesting() {
// eslint-disable-next-line no-undef
return Ember.testing || environment === "testing"; return Ember.testing || environment === "testing";
} }
// Generally means "before we migrated to Ember CLI" // Generally means "before we migrated to Ember CLI"
// eslint-disable-next-line no-undef
let _isLegacy = Ember.VERSION.startsWith("3.12"); let _isLegacy = Ember.VERSION.startsWith("3.12");
export function isLegacyEmber() { export function isLegacyEmber() {
return _isLegacy; return _isLegacy;

View File

@ -1,3 +1,4 @@
/* eslint-disable no-undef */
import { classify, dasherize } from "@ember/string"; import { classify, dasherize } from "@ember/string";
import deprecated from "discourse-common/lib/deprecated"; import deprecated from "discourse-common/lib/deprecated";
import { findHelper } from "discourse-common/lib/helpers"; import { findHelper } from "discourse-common/lib/helpers";

View File

@ -2,7 +2,8 @@ import Component from "@ember/component";
let componentArgs = { tagName: "div" }; let componentArgs = { tagName: "div" };
// TODO: Once we've moved to Ember CLI completely we can remove this. // TODO: Once we've moved to Ember CLI completely we can remove this block
// eslint-disable-next-line no-undef
if (!Ember.FEATURES.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) { if (!Ember.FEATURES.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) {
componentArgs = { tagName: "" }; componentArgs = { tagName: "" };
} }

View File

@ -1,7 +1,9 @@
import Component from "@ember/component";
import { import {
buildArgsWithDeprecations, buildArgsWithDeprecations,
renderedConnectorsFor, renderedConnectorsFor,
} from "discourse/lib/plugin-connectors"; } from "discourse/lib/plugin-connectors";
/** /**
A plugin outlet is an extension point for templates where other templates can A plugin outlet is an extension point for templates where other templates can
be inserted by plugins. be inserted by plugins.
@ -33,8 +35,6 @@ import {
The list of disabled plugins is returned via the `Site` singleton. The list of disabled plugins is returned via the `Site` singleton.
**/ **/
import Component from "@ember/component";
export default Component.extend({ export default Component.extend({
tagName: "", tagName: "",
connectorTagName: "", connectorTagName: "",

View File

@ -107,7 +107,9 @@ export default Component.extend({
let dasherized = dasherize(type); let dasherized = dasherize(type);
let templatePath = `components/${dasherized}`; let templatePath = `components/${dasherized}`;
let template = let template =
// eslint-disable-next-line no-undef
Ember.TEMPLATES[`${templatePath}`] || Ember.TEMPLATES[`${templatePath}`] ||
// eslint-disable-next-line no-undef
Ember.TEMPLATES[`javascripts/${templatePath}`]; Ember.TEMPLATES[`javascripts/${templatePath}`];
_components[type] = template ? dasherized : null; _components[type] = template ? dasherized : null;
return _components[type]; return _components[type];

View File

@ -10,6 +10,7 @@ export default {
return; return;
} }
// eslint-disable-next-line no-undef
Ember.EventDispatcher.reopen({ Ember.EventDispatcher.reopen({
events: { events: {
touchend: "touchEnd", touchend: "touchEnd",

View File

@ -8,6 +8,7 @@ export default {
return; return;
} }
// eslint-disable-next-line no-undef
Ember.LinkComponent.reopen({ Ember.LinkComponent.reopen({
attributeBindings: ["name"], attributeBindings: ["name"],
}); });

View File

@ -34,6 +34,7 @@ export default function (elem, siteSettings) {
mainClass: "mfp-zoom-in", mainClass: "mfp-zoom-in",
tClose: I18n.t("lightbox.close"), tClose: I18n.t("lightbox.close"),
tLoading: spinnerHTML, tLoading: spinnerHTML,
// eslint-disable-next-line no-undef
prependTo: Ember.testing && document.getElementById("ember-testing"), prependTo: Ember.testing && document.getElementById("ember-testing"),
gallery: { gallery: {

View File

@ -13,9 +13,9 @@ function loadWithTag(path, cb) {
let finished = false; let finished = false;
let s = document.createElement("script"); let s = document.createElement("script");
s.src = path; s.src = path;
if (Ember.Test) {
Ember.Test.registerWaiter(() => finished); // eslint-disable-next-line no-undef
} Ember.Test?.registerWaiter(() => finished);
s.onload = s.onreadystatechange = function (_, abort) { s.onload = s.onreadystatechange = function (_, abort) {
finished = true; finished = true;

View File

@ -60,12 +60,14 @@ function findClass(outletName, uniqueName) {
function buildConnectorCache() { function buildConnectorCache() {
_connectorCache = {}; _connectorCache = {};
// eslint-disable-next-line no-undef
findOutlets(Ember.TEMPLATES, (outletName, resource, uniqueName) => { findOutlets(Ember.TEMPLATES, (outletName, resource, uniqueName) => {
_connectorCache[outletName] = _connectorCache[outletName] || []; _connectorCache[outletName] = _connectorCache[outletName] || [];
_connectorCache[outletName].push({ _connectorCache[outletName].push({
outletName, outletName,
templateName: resource.replace("javascripts/", ""), templateName: resource.replace("javascripts/", ""),
// eslint-disable-next-line no-undef
template: Ember.TEMPLATES[resource], template: Ember.TEMPLATES[resource],
classNames: `${outletName}-outlet ${uniqueName}`, classNames: `${outletName}-outlet ${uniqueName}`,
connectorClass: findClass(outletName, uniqueName), connectorClass: findClass(outletName, uniqueName),

View File

@ -51,6 +51,8 @@ function reportToLogster(name, error) {
stacktrace: error.stack, stacktrace: error.stack,
}; };
// TODO: To be moved out into a logster-provided lib
// eslint-disable-next-line no-undef
Ember.$.ajax(getURL("/logs/report_js_error"), { Ember.$.ajax(getURL("/logs/report_js_error"), {
data, data,
type: "POST", type: "POST",

View File

@ -5,10 +5,12 @@ import { visit } from "@ember/test-helpers";
acceptance("CustomHTML template", function (needs) { acceptance("CustomHTML template", function (needs) {
needs.hooks.beforeEach(() => { needs.hooks.beforeEach(() => {
// eslint-disable-next-line no-undef
Ember.TEMPLATES["top"] = hbs`<span class='top-span'>TOP</span>`; Ember.TEMPLATES["top"] = hbs`<span class='top-span'>TOP</span>`;
}); });
needs.hooks.afterEach(() => { needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES["top"]; delete Ember.TEMPLATES["top"];
}); });

View File

@ -53,6 +53,7 @@ acceptance("Modal", function (needs) {
await triggerKeyEvent("#main-outlet", "keydown", 27); await triggerKeyEvent("#main-outlet", "keydown", 27);
assert.ok(!exists(".d-modal:visible"), "ESC should close the modal"); assert.ok(!exists(".d-modal:visible"), "ESC should close the modal");
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
"modal/not-dismissable" "modal/not-dismissable"
] = hbs`{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}`; ] = hbs`{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}`;
@ -77,6 +78,7 @@ acceptance("Modal", function (needs) {
}); });
test("rawTitle in modal panels", async function (assert) { test("rawTitle in modal panels", async function (assert) {
// eslint-disable-next-line no-undef
Ember.TEMPLATES["modal/test-raw-title-panels"] = hbs``; Ember.TEMPLATES["modal/test-raw-title-panels"] = hbs``;
const panels = [ const panels = [
{ id: "test1", rawTitle: "Test 1" }, { id: "test1", rawTitle: "Test 1" },
@ -95,7 +97,9 @@ acceptance("Modal", function (needs) {
}); });
test("modal title", async function (assert) { test("modal title", async function (assert) {
// eslint-disable-next-line no-undef
Ember.TEMPLATES["modal/test-title"] = hbs``; Ember.TEMPLATES["modal/test-title"] = hbs``;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
"modal/test-title-with-body" "modal/test-title-with-body"
] = hbs`{{#d-modal-body}}test{{/d-modal-body}}`; ] = hbs`{{#d-modal-body}}test{{/d-modal-body}}`;

View File

@ -48,23 +48,29 @@ acceptance("Plugin Outlet - Connector Class", function (needs) {
}, },
}); });
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/hello` `${PREFIX}/user-profile-primary/hello`
] = hbs`<span class='hello-username'>{{model.username}}</span> ] = hbs`<span class='hello-username'>{{model.username}}</span>
<button class='say-hello' {{action "sayHello"}}></button> <button class='say-hello' {{action "sayHello"}}></button>
<span class='hello-result'>{{hello}}</span>`; <span class='hello-result'>{{hello}}</span>`;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/hi` `${PREFIX}/user-profile-primary/hi`
] = hbs`<button class='say-hi' {{action "sayHi"}}></button> ] = hbs`<button class='say-hi' {{action "sayHi"}}></button>
<span class='hi-result'>{{hi}}</span>`; <span class='hi-result'>{{hi}}</span>`;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/dont-render` `${PREFIX}/user-profile-primary/dont-render`
] = hbs`I'm not rendered!`; ] = hbs`I'm not rendered!`;
}); });
needs.hooks.afterEach(() => { needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`]; delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`]; delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`]; delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
}); });

View File

@ -14,7 +14,9 @@ acceptance("Plugin Outlet - Decorator", function (needs) {
needs.user(); needs.user();
needs.hooks.beforeEach(() => { needs.hooks.beforeEach(() => {
// eslint-disable-next-line no-undef
Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`] = hbs`FOO`; Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`] = hbs`FOO`;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`] = hbs`BAR`; Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`] = hbs`BAR`;
withPluginApi("0.8.38", (api) => { withPluginApi("0.8.38", (api) => {
@ -37,7 +39,9 @@ acceptance("Plugin Outlet - Decorator", function (needs) {
}); });
needs.hooks.afterEach(() => { needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`]; delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`]; delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`];
}); });

View File

@ -15,12 +15,16 @@ const GOODBYE =
acceptance("Plugin Outlet - Multi Template", function (needs) { acceptance("Plugin Outlet - Multi Template", function (needs) {
needs.hooks.beforeEach(() => { needs.hooks.beforeEach(() => {
clearCache(); clearCache();
// eslint-disable-next-line no-undef
Ember.TEMPLATES[HELLO] = hbs`<span class='hello-span'>Hello</span>`; Ember.TEMPLATES[HELLO] = hbs`<span class='hello-span'>Hello</span>`;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[GOODBYE] = hbs`<span class='bye-span'>Goodbye</span>`; Ember.TEMPLATES[GOODBYE] = hbs`<span class='bye-span'>Goodbye</span>`;
}); });
needs.hooks.afterEach(() => { needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[HELLO]; delete Ember.TEMPLATES[HELLO];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[GOODBYE]; delete Ember.TEMPLATES[GOODBYE];
clearCache(); clearCache();
}); });

View File

@ -12,12 +12,14 @@ const CONNECTOR =
acceptance("Plugin Outlet - Single Template", function (needs) { acceptance("Plugin Outlet - Single Template", function (needs) {
needs.hooks.beforeEach(() => { needs.hooks.beforeEach(() => {
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
CONNECTOR CONNECTOR
] = hbs`<span class='hello-username'>{{model.username}}</span>`; ] = hbs`<span class='hello-username'>{{model.username}}</span>`;
}); });
needs.hooks.afterEach(() => { needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[CONNECTOR]; delete Ember.TEMPLATES[CONNECTOR];
}); });

View File

@ -18,6 +18,7 @@ document.addEventListener("discourse-booted", () => {
let setupTests = require("discourse/tests/setup-tests").default; let setupTests = require("discourse/tests/setup-tests").default;
const skippingCore = const skippingCore =
new URLSearchParams(window.location.search).get("qunit_skip_core") === "1"; new URLSearchParams(window.location.search).get("qunit_skip_core") === "1";
// eslint-disable-next-line no-undef
Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false; Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;
document.body.insertAdjacentHTML( document.body.insertAdjacentHTML(

View File

@ -12,6 +12,7 @@ function lookupTemplate(assert, name, expectedTemplate, message) {
function setTemplates(lookupTemplateStrings) { function setTemplates(lookupTemplateStrings) {
lookupTemplateStrings.forEach(function (lookupTemplateString) { lookupTemplateStrings.forEach(function (lookupTemplateString) {
// eslint-disable-next-line no-undef
Ember.TEMPLATES[lookupTemplateString] = lookupTemplateString; Ember.TEMPLATES[lookupTemplateString] = lookupTemplateString;
}); });
} }
@ -20,13 +21,16 @@ const DiscourseResolver = buildResolver("discourse");
module("Unit | Ember | resolver", function (hooks) { module("Unit | Ember | resolver", function (hooks) {
hooks.beforeEach(function () { hooks.beforeEach(function () {
// eslint-disable-next-line no-undef
originalTemplates = Ember.TEMPLATES; originalTemplates = Ember.TEMPLATES;
// eslint-disable-next-line no-undef
Ember.TEMPLATES = {}; Ember.TEMPLATES = {};
resolver = DiscourseResolver.create(); resolver = DiscourseResolver.create();
}); });
hooks.afterEach(function () { hooks.afterEach(function () {
// eslint-disable-next-line no-undef
Ember.TEMPLATES = originalTemplates; Ember.TEMPLATES = originalTemplates;
}); });

View File

@ -66,6 +66,7 @@ discourseModule("Unit | Utils | decorators", function (hooks) {
template: hbs`<NativeComponent @name="Jarek" />`, template: hbs`<NativeComponent @name="Jarek" />`,
beforeEach() { beforeEach() {
// eslint-disable-next-line no-undef
Ember.TEMPLATES[ Ember.TEMPLATES[
"components/native-component" "components/native-component"
] = hbs`<span class="native-component">{{this.text}}</span>`; ] = hbs`<span class="native-component">{{this.text}}</span>`;
@ -73,6 +74,7 @@ discourseModule("Unit | Utils | decorators", function (hooks) {
}, },
afterEach() { afterEach() {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES["components/native-component"]; delete Ember.TEMPLATES["components/native-component"];
}, },

View File

@ -20,6 +20,7 @@ define("ember-qunit", () => {
define("htmlbars-inline-precompile", () => { define("htmlbars-inline-precompile", () => {
return { return {
default: function (str) { default: function (str) {
// eslint-disable-next-line no-undef
return Ember.HTMLBars.compile(str[0]); return Ember.HTMLBars.compile(str[0]);
}, },
}; };

View File

@ -39,6 +39,7 @@ if (window.Logster) {
} else { } else {
window.Logster = { enabled: false }; window.Logster = { enabled: false };
} }
// eslint-disable-next-line no-undef
Ember.Test.adapter = window.QUnitAdapter.create(); Ember.Test.adapter = window.QUnitAdapter.create();
let createPretendServer = requirejs( let createPretendServer = requirejs(

View File

@ -7,8 +7,10 @@ export default Application.extend({
start() { start() {
// required for select kit to work without Ember CLI // required for select kit to work without Ember CLI
// eslint-disable-next-line no-undef
Object.keys(Ember.TEMPLATES).forEach((k) => { Object.keys(Ember.TEMPLATES).forEach((k) => {
if (k.indexOf("select-kit") === 0) { if (k.indexOf("select-kit") === 0) {
// eslint-disable-next-line no-undef
let template = Ember.TEMPLATES[k]; let template = Ember.TEMPLATES[k];
define(k, () => template); define(k, () => template);
} }

View File

@ -281,6 +281,7 @@ class Compiler {
} }
} }
// eslint-disable-next-line no-undef
const loader = typeof Ember !== "undefined" ? Ember.__loader.require : require; const loader = typeof Ember !== "undefined" ? Ember.__loader.require : require;
function compile(template, glimmer) { function compile(template, glimmer) {
@ -363,6 +364,7 @@ const WidgetHbsCompiler = function (babel) {
compile(template, WidgetHbsCompiler.glimmer) compile(template, WidgetHbsCompiler.glimmer)
); );
} catch (e) { } catch (e) {
// eslint-disable-next-line no-console
console.error("widget hbs error", e.toString()); console.error("widget hbs error", e.toString());
return error(path, state, e.toString()); return error(path, state, e.toString());
} }

View File

@ -29,6 +29,7 @@ export function allCategories() {
let paths = CATEGORIES.join("|"); let paths = CATEGORIES.join("|");
// Find a list of sections based on what templates are available // Find a list of sections based on what templates are available
// eslint-disable-next-line no-undef
Object.keys(Ember.TEMPLATES).forEach((e) => { Object.keys(Ember.TEMPLATES).forEach((e) => {
let regexp = new RegExp(`styleguide\/(${paths})\/(\\d+)?\\-?([^\\/]+)$`); let regexp = new RegExp(`styleguide\/(${paths})\/(\\d+)?\\-?([^\\/]+)$`);
let matches = e.match(regexp); let matches = e.match(regexp);