REFACTOR: applies discourse core coding practices (#82)

REFACTOR: applies discourse core coding practices (#82)

diff --git a/.eslintrc b/.eslintrc
index 8322028..7898fbf 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,105 +1,3 @@
 {
-  "env": {
-    "jasmine": true,
-    "node": true,
-    "mocha": true,
-    "browser": true,
-    "builtin": true
-  },
-  "parserOptions": {
-    "ecmaVersion": 7,
-    "sourceType": "module"
-  },
-  "globals":
-    {"Ember":true,
-    "jQuery":true,
-    "$":true,
-    "RSVP":true,
-    "Discourse":true,
-    "Em":true,
-    "PreloadStore":true,
-    "Handlebars":true,
-    "I18n":true,
-    "bootbox":true,
-    "module":true,
-    "moduleFor":true,
-    "moduleForComponent":true,
-    "Pretender":true,
-    "sandbox":true,
-    "controllerFor":true,
-    "test":true,
-    "ok":true,
-    "not":true,
-    "expect":true,
-    "equal":true,
-    "visit":true,
-    "andThen":true,
-    "click":true,
-    "currentPath":true,
-    "currentRouteName":true,
-    "currentURL":true,
-    "fillIn":true,
-    "keyEvent":true,
-    "triggerEvent":true,
-    "count":true,
-    "exists":true,
-    "visible":true,
-    "invisible":true,
-    "asyncRender":true,
-    "selectDropdown":true,
-    "asyncTestDiscourse":true,
-    "fixture":true,
-    "find":true,
-    "sinon":true,
-    "moment":true,
-    "start":true,
-    "_":true,
-    "alert":true,
-    "containsInstance":true,
-    "deepEqual":true,
-    "notEqual":true,
-    "define":true,
-    "require":true,
-    "requirejs":true,
-    "hasModule":true,
-    "Blob":true,
-    "File":true},
-  "rules": {
-    "block-scoped-var": 2,
-    "dot-notation": 0,
-    "eqeqeq": [
-      2,
-      "allow-null"
-    ],
-    "guard-for-in": 2,
-    "no-bitwise": 2,
-    "no-caller": 2,
-    "no-cond-assign": 0,
-    "no-debugger": 2,
-    "no-empty": 0,
-    "no-eval": 2,
-    "no-extend-native": 2,
-    "no-extra-parens": 0,
-    "no-irregular-whitespace": 2,
-    "no-iterator": 2,
-    "no-loop-func": 2,
-    "no-multi-str": 2,
-    "no-new": 2,
-    "no-plusplus": 0,
-    "no-proto": 2,
-    "no-script-url": 2,
-    "no-sequences": 2,
-    "no-shadow": 2,
-    "no-undef": 2,
-    "no-unused-vars": 2,
-    "no-with": 2,
-    "semi": 2,
-    "strict": 0,
-    "valid-typeof": 2,
-    "wrap-iife": [
-      2,
-      "inside"
-    ]
-  },
-  "parser": "babel-eslint"
+  "extends": "eslint-config-discourse"
 }
diff --git a/.gitignore b/.gitignore
index 2a61502..c2b5b3a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ Gemfile.lock
 .DS_Store
 *.swp
 .rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
+node_modules
diff --git a/assets/javascripts/discourse/components/ad-component.js.es6 b/assets/javascripts/discourse/components/ad-component.js.es6
index 3142295..45b8c5f 100644
--- a/assets/javascripts/discourse/components/ad-component.js.es6
+++ b/assets/javascripts/discourse/components/ad-component.js.es6
@@ -1,4 +1,4 @@
-import computed from "ember-addons/ember-computed-decorators";
+import discourseComputed from "discourse-common/utils/decorators";
 
 export default Ember.Component.extend({
   router: Ember.inject.service(),
@@ -23,7 +23,7 @@ export default Ember.Component.extend({
     "router.currentRoute.parent.attributes.category.read_restricted"
   ),
 
-  @computed(
+  @discourseComputed(
     "router.currentRoute.attributes.__type",
     "router.currentRoute.attributes.id"
   )
@@ -33,12 +33,12 @@ export default Ember.Component.extend({
     }
   },
 
-  @computed("router.currentRoute.parent.attributes.archetype")
+  @discourseComputed("router.currentRoute.parent.attributes.archetype")
   isPersonalMessage(topicType) {
     return topicType === "private_message";
   },
 
-  @computed("currentUser.groups")
+  @discourseComputed("currentUser.groups")
   showToGroups(groups) {
     const currentUser = Discourse.User.current();
 
@@ -67,7 +67,7 @@ export default Ember.Component.extend({
     return !currentGroups.any(g => noAdsGroups.includes(g));
   },
 
-  @computed(
+  @discourseComputed(
     "currentCategoryId",
     "topicTagsDisableAds",
     "topicListTag",
diff --git a/assets/javascripts/discourse/components/ad-slot.js.es6 b/assets/javascripts/discourse/components/ad-slot.js.es6
index b34f202..741ce93 100644
--- a/assets/javascripts/discourse/components/ad-slot.js.es6
+++ b/assets/javascripts/discourse/components/ad-slot.js.es6
@@ -1,8 +1,5 @@
 import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
-import {
-  default as computed,
-  observes
-} from "ember-addons/ember-computed-decorators";
+import discourseComputed, { observes } from "discourse-common/utils/decorators";
 
 const adConfig = Ember.Object.create({
   "google-adsense": {
@@ -85,7 +82,7 @@ export default AdComponent.extend({
    * For a given ad placement and optionally a post number if in between posts,
    * list all ad network names that are configured to show there.
    */
-  @computed("placement", "postNumber")
+  @discourseComputed("placement", "postNumber")
   availableAdTypes(placement, postNumber) {
     let types = [];
     const houseAds = this.site.get("house_creatives"),
@@ -167,7 +164,7 @@ export default AdComponent.extend({
    * in the given ad placement. It handles alternating between house ads
    * and other ad networks.
    */
-  @computed("placement", "availableAdTypes", "needsUpdate")
+  @discourseComputed("placement", "availableAdTypes", "needsUpdate")
   adComponents(placement, availableAdTypes) {
     if (
       !availableAdTypes.includes("house-ad") ||
diff --git a/assets/javascripts/discourse/components/adbutler-ad.js.es6 b/assets/javascripts/discourse/components/adbutler-ad.js.es6
index 6743e36..5f59eeb 100644
--- a/assets/javascripts/discourse/components/adbutler-ad.js.es6
+++ b/assets/javascripts/discourse/components/adbutler-ad.js.es6
@@ -1,8 +1,5 @@
 import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
-import {
-  default as computed,
-  observes
-} from "ember-addons/ember-computed-decorators";
+import discourseComputed, { observes } from "discourse-common/utils/decorators";
 import loadScript from "discourse/lib/load-script";
 
 const publisherId = Discourse.SiteSettings.adbutler_publisher_id;
@@ -117,7 +114,7 @@ export default AdComponent.extend({
     }
   },
 
-  @computed("currentUser.trust_level")
+  @discourseComputed("currentUser.trust_level")
   showToTrustLevel(trustLevel) {
     return !(
       trustLevel &&
@@ -125,7 +122,7 @@ export default AdComponent.extend({
     );
   },
 
-  @computed(
+  @discourseComputed(
     "showToTrustLevel",
     "showToGroups",
     "showAfterPost",
@@ -141,7 +138,7 @@ export default AdComponent.extend({
     );
   },
 
-  @computed("postNumber")
+  @discourseComputed("postNumber")
   showAfterPost(postNumber) {
     if (!postNumber) {
       return true;
diff --git a/assets/javascripts/discourse/components/amazon-product-links.js.es6 b/assets/javascripts/discourse/components/amazon-product-links.js.es6
index ce74bcf..b192c32 100644
--- a/assets/javascripts/discourse/components/amazon-product-links.js.es6
+++ b/assets/javascripts/discourse/components/amazon-product-links.js.es6
@@ -1,5 +1,5 @@
 import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
-import computed from "ember-addons/ember-computed-decorators";
+import discourseComputed from "discourse-common/utils/decorators";
 
 const data = {
   "topic-list-top": {},
@@ -157,32 +157,32 @@ export default AdComponent.extend({
     this._super();
   },
 
-  @computed("amazon_width", "amazon_height")
+  @discourseComputed("amazon_width", "amazon_height")
   adWrapperStyle(w, h) {
     return `width: ${w}px; height: ${h}px;`.htmlSafe();
   },
 
-  @computed("mobile_amazon_width", "mobile_amazon_height")
+  @discourseComputed("mobile_amazon_width", "mobile_amazon_height")
   adWrapperStyleMobile(w, h) {
     return `width: ${w}px; height: ${h}px;`.htmlSafe();
   },
 
-  @computed("mobile_amazon_width")

[... diff too long, it was truncated ...]

GitHub sha: 27079916

1 Like

This commit appears in #82 which was merged by jjaffeux.