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",
"currentUser": "off",
"Discourse": "off",
"Ember": "off",
"exists": "off",
"fillIn": "off",
"find": "off",

View File

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

View File

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

View File

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

View File

@ -2,7 +2,8 @@ import Component from "@ember/component";
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) {
componentArgs = { tagName: "" };
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,9 +13,9 @@ function loadWithTag(path, cb) {
let finished = false;
let s = document.createElement("script");
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) {
finished = true;

View File

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

View File

@ -51,6 +51,8 @@ function reportToLogster(name, error) {
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"), {
data,
type: "POST",

View File

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

View File

@ -53,6 +53,7 @@ acceptance("Modal", function (needs) {
await triggerKeyEvent("#main-outlet", "keydown", 27);
assert.ok(!exists(".d-modal:visible"), "ESC should close the modal");
// eslint-disable-next-line no-undef
Ember.TEMPLATES[
"modal/not-dismissable"
] = 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) {
// eslint-disable-next-line no-undef
Ember.TEMPLATES["modal/test-raw-title-panels"] = hbs``;
const panels = [
{ id: "test1", rawTitle: "Test 1" },
@ -95,7 +97,9 @@ acceptance("Modal", function (needs) {
});
test("modal title", async function (assert) {
// eslint-disable-next-line no-undef
Ember.TEMPLATES["modal/test-title"] = hbs``;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[
"modal/test-title-with-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[
`${PREFIX}/user-profile-primary/hello`
] = hbs`<span class='hello-username'>{{model.username}}</span>
<button class='say-hello' {{action "sayHello"}}></button>
<span class='hello-result'>{{hello}}</span>`;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/hi`
] = hbs`<button class='say-hi' {{action "sayHi"}}></button>
<span class='hi-result'>{{hi}}</span>`;
// eslint-disable-next-line no-undef
Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/dont-render`
] = hbs`I'm not rendered!`;
});
needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
});

View File

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

View File

@ -15,12 +15,16 @@ const GOODBYE =
acceptance("Plugin Outlet - Multi Template", function (needs) {
needs.hooks.beforeEach(() => {
clearCache();
// eslint-disable-next-line no-undef
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>`;
});
needs.hooks.afterEach(() => {
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[HELLO];
// eslint-disable-next-line no-undef
delete Ember.TEMPLATES[GOODBYE];
clearCache();
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,8 +7,10 @@ export default Application.extend({
start() {
// required for select kit to work without Ember CLI
// eslint-disable-next-line no-undef
Object.keys(Ember.TEMPLATES).forEach((k) => {
if (k.indexOf("select-kit") === 0) {
// eslint-disable-next-line no-undef
let template = Ember.TEMPLATES[k];
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;
function compile(template, glimmer) {
@ -363,6 +364,7 @@ const WidgetHbsCompiler = function (babel) {
compile(template, WidgetHbsCompiler.glimmer)
);
} catch (e) {
// eslint-disable-next-line no-console
console.error("widget hbs error", e.toString());
return error(path, state, e.toString());
}

View File

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