DEV: Ember linting - disallow Ember.* variable usage (#8782)

This commit is contained in:
Mark VanLandingham 2020-02-05 10:14:42 -06:00 committed by GitHub
parent 88779d849f
commit 499b57a9ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 97 additions and 49 deletions

View File

@ -1,3 +1,7 @@
{
"extends": "eslint-config-discourse"
"extends": "eslint-config-discourse",
"plugins": ["discourse-ember"],
"rules": {
"discourse-ember/global-ember": 2
}
}

View File

@ -1,6 +1,7 @@
import { popupAjaxError } from "discourse/lib/ajax-error";
import Controller from "@ember/controller";
export default Ember.Controller.extend({
export default Controller.extend({
actions: {
revokeKey(key) {
key.revoke().catch(popupAjaxError);

View File

@ -1,7 +1,8 @@
import discourseComputed from "discourse-common/utils/decorators";
import Controller from "@ember/controller";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
export default Controller.extend({
userModes: [
{ id: "all", name: I18n.t("admin.api.all_users") },
{ id: "single", name: I18n.t("admin.api.single_user") }

View File

@ -1,8 +1,10 @@
import { bufferedProperty } from "discourse/mixins/buffered-content";
import Controller from "@ember/controller";
import { isEmpty } from "@ember/utils";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { empty } from "@ember/object/computed";
export default Ember.Controller.extend(bufferedProperty("model"), {
export default Controller.extend(bufferedProperty("model"), {
isNew: empty("model.id"),
actions: {
@ -21,7 +23,7 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
cancel() {
const id = this.get("userField.id");
if (Ember.isEmpty(id)) {
if (isEmpty(id)) {
this.destroyAction(this.userField);
} else {
this.rollbackBuffer();

View File

@ -1,10 +1,10 @@
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import { reads } from "@ember/object/computed";
import { inject } from "@ember/controller";
import Controller from "@ember/controller";
import Controller, { inject } from "@ember/controller";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { bufferedProperty } from "discourse/mixins/buffered-content";
import { propertyNotEqual } from "discourse/lib/computed";
import { run } from "@ember/runloop";
export default Controller.extend(bufferedProperty("model"), {
adminBadges: inject(),
@ -23,7 +23,7 @@ export default Controller.extend(bufferedProperty("model"), {
// this is needed because the model doesnt have default values
// and as we are using a bufferedProperty it's not accessible
// in any other way
Ember.run.next(() => {
run.next(() => {
if (this.model) {
if (!this.model.badge_type_id) {
this.model.set(

View File

@ -13,6 +13,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import showModal from "discourse/lib/show-modal";
import ThemeSettings from "admin/models/theme-settings";
import { THEMES, COMPONENTS } from "admin/models/theme";
import EmberObject from "@ember/object";
const THEME_UPLOAD_VAR = 2;
@ -67,7 +68,7 @@ export default Controller.extend({
@discourseComputed("model.parentThemes.[]")
relativesSelectorSettingsForComponent() {
return Ember.Object.create({
return EmberObject.create({
list_type: "compact",
type: "list",
preview: null,
@ -85,7 +86,7 @@ export default Controller.extend({
@discourseComputed("model.parentThemes.[]")
relativesSelectorSettingsForTheme() {
return Ember.Object.create({
return EmberObject.create({
list_type: "compact",
type: "list",
preview: null,

View File

@ -1,4 +1,6 @@
export default Ember.Route.extend({
import Route from "@ember/routing/route";
export default Route.extend({
model(params) {
return this.store.find("api-key", params.api_key_id);
}

View File

@ -1,7 +1,8 @@
import { bind } from "@ember/runloop";
import { getOwner } from "discourse-common/lib/get-owner";
import Mixin from "@ember/object/mixin";
export default Ember.Mixin.create({
export default Mixin.create({
ready() {
this._super(...arguments);

View File

@ -108,6 +108,10 @@ var define, requirejs;
},
"@ember/error": {
default: Ember.error
},
"@ember/object/internals": {
guidFor: Ember.guidFor
}
};
}

View File

@ -2,6 +2,7 @@ import { bind, cancel } from "@ember/runloop";
import Component from "@ember/component";
import LogsNotice from "discourse/services/logs-notice";
import EmberObject from "@ember/object";
import { computed } from "@ember/object";
const _pluginNotices = [];
@ -58,7 +59,7 @@ export default Component.extend({
this._tearDownObservers();
},
notices: Ember.computed(
notices: computed(
"site.isReadOnly",
"siteSettings.disable_emails",
"logNotice.{id,text,hidden}",

View File

@ -1,4 +1,6 @@
export default Ember.Component.extend({
import Component from "@ember/component";
export default Component.extend({
actions: {
onChange(tags) {
this.valueChanged &&

View File

@ -1,7 +1,7 @@
import Controller from "@ember/controller";
import Controller, { inject } from "@ember/controller";
export default Controller.extend({
tagGroups: Ember.inject.controller(),
tagGroups: inject(),
actions: {
onSave() {

View File

@ -1,5 +1,6 @@
import EmberObject from "@ember/object";
import { defaultHomepage } from "discourse/lib/utilities";
import { guidFor } from "@ember/object/internals";
let popstateFired = false;
const supportsHistoryState = window.history && "state" in window.history;
const popstateCallbacks = [];
@ -174,7 +175,7 @@ const DiscourseLocation = EmberObject.extend({
@param callback {Function}
*/
onUpdateURL(callback) {
const guid = Ember.guidFor(this);
const guid = guidFor(this);
$(window).on(`popstate.ember-location-${guid}`, () => {
const url = this.getURL();
@ -215,7 +216,7 @@ const DiscourseLocation = EmberObject.extend({
willDestroy() {
this._super(...arguments);
const guid = Ember.guidFor(this);
const guid = guidFor(this);
$(window).off(`popstate.ember-location-${guid}`);
}
});

View File

@ -1,5 +1,6 @@
import { run } from "@ember/runloop";
import { ajax } from "discourse/lib/ajax";
const { debounce } = Ember.run;
const { debounce } = run;
let _queue = [];
let _processing = 0;

View File

@ -1,10 +1,11 @@
import RestrictedUserRoute from "discourse/routes/restricted-user";
import { set } from "@ember/object";
export default RestrictedUserRoute.extend({
showFooter: true,
setupController(controller, model) {
if (!model.user_option.timezone) {
Ember.set(model, "user_option.timezone", moment.tz.guess());
set(model, "user_option.timezone", moment.tz.guess());
}
controller.set("model", model);

View File

@ -8,6 +8,7 @@ import {
import Draft from "discourse/models/draft";
import { computed } from "@ember/object";
import { camelize } from "@ember/string";
import { isEmpty } from "@ember/utils";
// Component can get destroyed and lose state
let _topicSnapshot = null;
@ -49,7 +50,7 @@ export default DropdownSelectBoxComponent.extend({
_postSnapshot = this.get("composerModel.post");
}
if (Ember.isEmpty(this.content)) {
if (isEmpty(this.content)) {
this.set("selectKit.isHidden", true);
}
},

View File

@ -1,9 +1,12 @@
import { computed, default as EmberObject } from "@ember/object";
import Component from "@ember/component";
import deprecated from "discourse-common/lib/deprecated";
const { get, isNone, makeArray } = Ember;
import { makeArray } from "discourse-common/lib/helpers";
import { get } from "@ember/object";
import UtilsMixin from "select-kit/mixins/utils";
import PluginApiMixin from "select-kit/mixins/plugin-api";
import Mixin from "@ember/object/mixin";
import { isEmpty, isNone } from "@ember/utils";
import {
next,
debounce,
@ -26,7 +29,7 @@ export const MAIN_COLLECTION = "MAIN_COLLECTION";
export const ERRORS_COLLECTION = "ERRORS_COLLECTION";
const EMPTY_OBJECT = Object.freeze({});
const SELECT_KIT_OPTIONS = Ember.Mixin.create({
const SELECT_KIT_OPTIONS = Mixin.create({
mergedProperties: ["selectKitOptions"],
selectKitOptions: EMPTY_OBJECT
});
@ -220,7 +223,7 @@ export default Component.extend(
);
this.selectKit.setProperties({
hasSelection: !Ember.isEmpty(this.value),
hasSelection: !isEmpty(this.value),
noneItem: this._modifyNoSelectionWrapper()
});
@ -572,7 +575,7 @@ export default Component.extend(
}
}
const hasNoContent = Ember.isEmpty(content);
const hasNoContent = isEmpty(content);
if (
this.selectKit.hasSelection &&

View File

@ -1,5 +1,6 @@
import Component from "@ember/component";
import { computed } from "@ember/object";
import { bind } from "@ember/runloop";
export default Component.extend({
layoutName: "select-kit/templates/components/select-kit/select-kit-body",
@ -13,10 +14,7 @@ export default Component.extend({
init() {
this._super(...arguments);
this.handleRootMouseDownHandler = Ember.run.bind(
this,
this.handleRootMouseDown
);
this.handleRootMouseDownHandler = bind(this, this.handleRootMouseDown);
},
didInsertElement() {

View File

@ -2,6 +2,7 @@ import Component from "@ember/component";
import { propertyEqual } from "discourse/lib/computed";
import { computed } from "@ember/object";
import { makeArray } from "discourse-common/lib/helpers";
import { guidFor } from "@ember/object/internals";
import UtilsMixin from "select-kit/mixins/utils";
export default Component.extend(UtilsMixin, {
@ -30,7 +31,7 @@ export default Component.extend(UtilsMixin, {
}),
guid: computed("item", function() {
return Ember.guidFor(this.item);
return guidFor(this.item);
}),
ariaLabel: computed("item.ariaLabel", "title", function() {

View File

@ -3,6 +3,7 @@ import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import Mixin from "@ember/object/mixin";
import { makeArray } from "discourse-common/lib/helpers";
import { isEmpty } from "@ember/utils";
export default Mixin.create({
searchTags(url, data, callback) {
@ -55,7 +56,7 @@ export default Mixin.create({
}
const toLowerCaseOrUndefined = string => {
return Ember.isEmpty(string) ? undefined : string.toLowerCase();
return isEmpty(string) ? undefined : string.toLowerCase();
};
const inCollection = content

View File

@ -1,5 +1,5 @@
import Mixin from "@ember/object/mixin";
const { get } = Ember;
import { get } from "@ember/object";
export default Mixin.create({
defaultItem(value, name) {
@ -57,7 +57,7 @@ export default Mixin.create({
},
findValue(content, item) {
const property = Ember.get(this.selectKit, "valueProperty");
const property = get(this.selectKit, "valueProperty");
if (!property) {
if (content.indexOf(item) > -1) {

View File

@ -43,6 +43,7 @@
"@arkweid/lefthook": "^0.6.3",
"chrome-launcher": "^0.12.0",
"chrome-remote-interface": "^0.25",
"eslint-plugin-discourse-ember": "0.0.3",
"eslint-config-discourse": "1.1.0",
"lodash-cli": "https://github.com/lodash-archive/lodash-cli.git",
"pretender": "^1.6",

View File

@ -1,5 +1,6 @@
import selectKit from "helpers/select-kit-helper";
import componentTest from "helpers/component-test";
import EmberObject from "@ember/object";
moduleForComponent("badge-title", { integration: true });
@ -10,10 +11,10 @@ componentTest("badge title", {
beforeEach() {
this.set("subject", selectKit());
this.set("selectableUserBadges", [
Ember.Object.create({
EmberObject.create({
badge: { name: "(none)" }
}),
Ember.Object.create({
EmberObject.create({
id: 42,
badge_id: 102,
badge: { name: "Test" }

View File

@ -5,6 +5,7 @@ import {
NO_CATEGORIES_ID,
ALL_CATEGORIES_ID
} from "select-kit/components/category-drop";
import { set } from "@ember/object";
testSelectKitModule("category-drop");
@ -82,8 +83,8 @@ componentTest("[not staff - TL0] displayCategoryDescription", {
template: template(),
beforeEach() {
Ember.set(this.currentUser, "staff", false);
Ember.set(this.currentUser, "trustLevel", 0);
set(this.currentUser, "staff", false);
set(this.currentUser, "trustLevel", 0);
initCategories(this);
},
@ -103,8 +104,8 @@ componentTest("[not staff - TL1] displayCategoryDescription", {
template: template(),
beforeEach() {
Ember.set(this.currentUser, "staff", false);
Ember.set(this.currentUser, "trustLevel", 1);
set(this.currentUser, "staff", false);
set(this.currentUser, "trustLevel", 1);
initCategories(this);
},
@ -124,8 +125,8 @@ componentTest("[staff - TL0] displayCategoryDescription", {
template: template(),
beforeEach() {
Ember.set(this.currentUser, "staff", true);
Ember.set(this.currentUser, "trustLevel", 0);
set(this.currentUser, "staff", true);
set(this.currentUser, "trustLevel", 0);
initCategories(this);
},

View File

@ -1,11 +1,12 @@
import componentTest from "helpers/component-test";
import { testSelectKitModule } from "./select-kit-test-helper";
import Site from "discourse/models/site";
import { set } from "@ember/object";
testSelectKitModule("tag-drop", {
beforeEach() {
const site = Site.current();
Ember.set(site, "top_tags", ["jeff", "neil", "arpit", "régis"]);
set(site, "top_tags", ["jeff", "neil", "arpit", "régis"]);
const response = object => {
return [200, { "Content-Type": "application/json" }, object];

View File

@ -4,6 +4,7 @@ import Topic from "discourse/models/topic";
import PostStream from "discourse/models/post-stream";
import { Placeholder } from "discourse/lib/posts-with-placeholders";
import User from "discourse/models/user";
import { Promise } from "rsvp";
moduleFor("controller:topic", "controller:topic", {
needs: [
@ -534,7 +535,7 @@ QUnit.test(
reply_count: 3,
destroy: () => {
destroyed = true;
return Ember.RSVP.Promise.resolve();
return Promise.resolve();
}
});

View File

@ -1,3 +1,4 @@
import { set } from "@ember/object";
export default function(helpers) {
const { response } = helpers;
@ -136,7 +137,7 @@ export default function(helpers) {
this.put("/review/:id", request => {
let result = { payload: {} };
Object.entries(JSON.parse(request.requestBody).reviewable).forEach(t => {
Ember.set(result, t[0], t[1]);
set(result, t[0], t[1]);
});
return response(200, result);
});

View File

@ -1,3 +1,5 @@
import { isEmpty } from "@ember/utils";
function checkSelectKitIsNotExpanded(selector) {
if (find(selector).hasClass("is-expanded")) {
// eslint-disable-next-line no-console
@ -90,7 +92,7 @@ function rowHelper(row) {
},
value() {
const value = row.attr("data-value");
return Ember.isEmpty(value) ? null : value;
return isEmpty(value) ? null : value;
},
exists() {
return exists(row);
@ -105,7 +107,7 @@ function headerHelper(header) {
return {
value() {
const value = header.attr("data-value");
return Ember.isEmpty(value) ? null : value;
return isEmpty(value) ? null : value;
},
name() {
return header.attr("data-name");

View File

@ -1,5 +1,6 @@
import PreloadStore from "preload-store";
import { asyncTestDiscourse } from "helpers/qunit-helpers";
import { Promise } from "rsvp";
QUnit.module("preload-store", {
beforeEach() {
@ -56,7 +57,7 @@ asyncTestDiscourse(
assert.expect(1);
const finder = function() {
return new Ember.RSVP.Promise(function(resolve) {
return new Promise(function(resolve) {
resolve("hahahah");
});
};
@ -75,7 +76,7 @@ asyncTestDiscourse(
assert.expect(1);
const finder = function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
reject("error");
});
};

View File

@ -2,6 +2,7 @@ import { next } from "@ember/runloop";
import { moduleForWidget, widgetTest } from "helpers/widget-test";
import { createWidget } from "discourse/widgets/widget";
import { withPluginApi } from "discourse/lib/plugin-api";
import { Promise } from "rsvp";
import hbs from "discourse/widgets/hbs-compiler";
moduleForWidget("base");
@ -159,7 +160,7 @@ widgetTest("widget update with promise", {
`,
click() {
return new Ember.RSVP.Promise(resolve => {
return new Promise(resolve => {
next(() => {
this.state.name = "Robin";
resolve();

View File

@ -741,6 +741,13 @@ eslint-config-discourse@1.1.0:
eslint "^4.19"
prettier "^1.19.1"
eslint-plugin-discourse-ember@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-discourse-ember/-/eslint-plugin-discourse-ember-0.0.3.tgz#69e5876c2ece38ab3d6c4a05f0a20a7dc4c21e37"
integrity sha512-EFwWU4FlOSLBa4RolKZL8QD1eGOnvSkACLt4Big+o1ZUIpW7gGvfnJPtxkbaQ4XmhtZ5HetYt6862vVqhUMv9A==
dependencies:
requireindex "~1.1.0"
eslint-plugin-lodash@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-lodash/-/eslint-plugin-lodash-6.0.0.tgz#70fa487ab632e62627ecf01ad3e85c228e3ab9d3"
@ -2075,6 +2082,11 @@ require-uncached@^1.0.3:
caller-path "^0.1.0"
resolve-from "^1.0.0"
requireindex@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.1.0.tgz#e5404b81557ef75db6e49c5a72004893fe03e162"
integrity sha1-5UBLgVV+91225JxacgBIk/4D4WI=
resolve-dir@^1.0.0, resolve-dir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43"