diff --git a/.eslintrc b/.eslintrc index 844933e68b1..d84c9eb64c0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,80 +1,79 @@ { "env": { - "jasmine": true, - "node": true, - "mocha": true, "browser": true, "builtin": true, - "es6": true + "es6": true, + "jasmine": true, + "mocha": true, + "node": true, }, "parserOptions": { "ecmaVersion": 7, "sourceType": "module" }, - "globals": - {"Ember":true, - "jQuery":true, - "$":true, - "QUnit":true, - "RSVP":true, - "Discourse":true, - "Em":true, - "Handlebars":true, - "I18n":true, - "bootbox":true, - "moduleFor":true, - "moduleForComponent":true, - "Pretender":true, - "sandbox":true, - "controllerFor":true, - "test":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, - "selectKit":true, - "expandSelectKit":true, - "collapseSelectKit":true, - "selectKitSelectRowByValue":true, - "selectKitSelectRowByName":true, - "selectKitSelectRowByIndex":true, - "keyboardHelper":true, - "selectKitSelectNoneRow":true, - "selectKitFillInFilter":true, - "asyncTestDiscourse":true, - "fixture":true, - "find":true, - "sinon":true, - "moment":true, - "_":true, - "alert":true, - "define":true, - "require":true, - "requirejs":true, - "hasModule":true, - "Blob":true, - "File":true}, + "globals": { + "$": true, + "_": true, + "andThen": true, + "asyncRender": true, + "asyncTestDiscourse": true, + "Blob": true, + "bootbox": true, + "click": true, + "collapseSelectKit": true, + "controllerFor": true, + "count": true, + "currentPath": true, + "currentRouteName": true, + "currentURL": true, + "define": true, + "Discourse": true, + "Em": true, + "Ember": true, + "exists": true, + "expandSelectKit": true, + "File": true, + "fillIn": true, + "find": true, + "fixture": true, + "Handlebars": true, + "hasModule": true, + "I18n": true, + "invisible": true, + "jQuery": true, + "keyboardHelper": true, + "keyEvent": true, + "moduleFor": true, + "moduleForComponent": true, + "moment": true, + "Pretender": true, + "QUnit": true, + "require": true, + "requirejs": true, + "RSVP": true, + "sandbox": true, + "selectKit": true, + "selectKitFillInFilter": true, + "selectKitSelectNoneRow": true, + "selectKitSelectRowByIndex": true, + "selectKitSelectRowByName": true, + "selectKitSelectRowByValue": true, + "sinon": true, + "test": true, + "triggerEvent": true, + "visible": true, + "visit": true, + }, "rules": { "block-scoped-var": 2, "dot-notation": 0, - "eqeqeq": [ - 2, - "allow-null" - ], + "eqeqeq": [2, "allow-null"], "guard-for-in": 2, + "no-alert": 2, "no-bitwise": 2, "no-caller": 2, "no-cond-assign": 0, + "no-console": 2, "no-debugger": 2, "no-empty": 0, "no-eval": 2, @@ -84,6 +83,7 @@ "no-irregular-whitespace": 2, "no-iterator": 2, "no-loop-func": 2, + "no-mixed-spaces-and-tabs": 2, "no-multi-str": 2, "no-new": 2, "no-plusplus": 0, @@ -91,19 +91,15 @@ "no-script-url": 2, "no-sequences": 2, "no-shadow": 2, + "no-this-before-super": 2, + "no-trailing-spaces": 2, "no-undef": 2, "no-unused-vars": 2, "no-with": 2, - "no-this-before-super": 2, "semi": 2, "strict": 0, "valid-typeof": 2, - "wrap-iife": [ - 2, - "inside" - ], - "no-mixed-spaces-and-tabs": 2, - "no-trailing-spaces": 2 + "wrap-iife": [2, "inside"], }, "parser": "babel-eslint" } diff --git a/app/assets/javascripts/admin/controllers/modals/admin-flags-received.js.es6 b/app/assets/javascripts/admin/controllers/modals/admin-flags-received.js.es6 index c4c3e79b72f..f4c8226733b 100644 --- a/app/assets/javascripts/admin/controllers/modals/admin-flags-received.js.es6 +++ b/app/assets/javascripts/admin/controllers/modals/admin-flags-received.js.es6 @@ -11,7 +11,6 @@ export default Ember.Controller.extend({ }) .then(result => { this.set("loadingFlags", false); - console.log(result); this.set("flaggedPosts", result); }); } diff --git a/app/assets/javascripts/discourse-common/lib/deprecated.js.es6 b/app/assets/javascripts/discourse-common/lib/deprecated.js.es6 index 02daf6ebdac..ecb2f152d51 100644 --- a/app/assets/javascripts/discourse-common/lib/deprecated.js.es6 +++ b/app/assets/javascripts/discourse-common/lib/deprecated.js.es6 @@ -1,3 +1,3 @@ export default function deprecated(msg) { - console.warn(`DEPRECATION: ${msg}`); + console.warn(`DEPRECATION: ${msg}`); // eslint-disable-line no-console } diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js index dee43e5a9c1..3a86a00da13 100644 --- a/app/assets/javascripts/discourse-loader.js +++ b/app/assets/javascripts/discourse-loader.js @@ -119,7 +119,7 @@ var define, requirejs; if (!mod) { var moved = MOVED_MODULES[name]; if (moved) { - console.warn("DEPRECATION: `" + name + "` was moved to `" + moved + "`"); + console.warn("DEPRECATION: `" + name + "` was moved to `" + moved + "`"); // eslint-disable-line no-console } mod = registry[moved]; } diff --git a/app/assets/javascripts/discourse/components/mount-widget.js.es6 b/app/assets/javascripts/discourse/components/mount-widget.js.es6 index 33b6b312f82..92e17685e6a 100644 --- a/app/assets/javascripts/discourse/components/mount-widget.js.es6 +++ b/app/assets/javascripts/discourse/components/mount-widget.js.es6 @@ -30,6 +30,7 @@ export default Ember.Component.extend({ queryRegistry(name) || this.register.lookupFactory(`widget:${name}`); if (!this._widgetClass) { + // eslint-disable-next-line no-console console.error(`Error: Could not find widget: ${name}`); } @@ -130,6 +131,7 @@ export default Ember.Component.extend({ this.dirtyKeys.renderedKey("*"); if (this.profileWidget) { + // eslint-disable-next-line no-console console.log(new Date().getTime() - t0); } } diff --git a/app/assets/javascripts/discourse/components/share-popup.js.es6 b/app/assets/javascripts/discourse/components/share-popup.js.es6 index 7980b2abe31..757fc377a4b 100644 --- a/app/assets/javascripts/discourse/components/share-popup.js.es6 +++ b/app/assets/javascripts/discourse/components/share-popup.js.es6 @@ -128,9 +128,7 @@ export default Ember.Component.extend({ // use native webshare only when the user clicks on the "chain" icon // navigator.share needs HTTPS, returns undefined on HTTP if (navigator.share && !$currentTarget.hasClass("post-date")) { - this._webShare(url).catch(error => { - console.warn("Error sharing", error); - + this._webShare(url).catch(() => { // if navigator fails for unexpected reason fallback to popup this._showUrl($currentTarget, url); }); diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 25927a467f3..9734f1285f6 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -703,9 +703,9 @@ export default Ember.Controller.extend({ opts = opts || {}; if (!opts.draftKey) { - alert("composer was opened without a draft key"); throw new Error("composer opened without a proper draft key"); } + const self = this; let composerModel = this.get("model"); diff --git a/app/assets/javascripts/discourse/helpers/raw.js.es6 b/app/assets/javascripts/discourse/helpers/raw.js.es6 index ad9ed698d81..db6b48d3849 100644 --- a/app/assets/javascripts/discourse/helpers/raw.js.es6 +++ b/app/assets/javascripts/discourse/helpers/raw.js.es6 @@ -40,6 +40,7 @@ registerUnbound("raw", function(templateName, params) { const container = Discourse.__container__; const template = findRawTemplate(templateName); if (!template) { + // eslint-disable-next-line no-console console.warn("Could not find raw template: " + templateName); return; } diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index fb62d4d3e39..685ae3d6250 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -60,6 +60,7 @@ class PluginApi { opts = opts || {}; if (this.container.cache[resolverName]) { + // eslint-disable-next-line no-console console.warn( `"${resolverName}" was already cached in the container. Changes won't be applied.` ); @@ -68,6 +69,7 @@ class PluginApi { const klass = this.container.factoryFor(resolverName); if (!klass) { if (!opts.ignoreMissing) { + // eslint-disable-next-line no-console console.warn(`"${resolverName}" was not found by modifyClass`); } return; @@ -686,6 +688,7 @@ class PluginApi { */ addNavigationBarItem(item) { if (!item["name"]) { + // eslint-disable-next-line no-console console.warn( "A 'name' is required when adding a Navigation Bar Item.", item @@ -806,6 +809,7 @@ function getPluginApi(version) { } return _pluginv01; } else { + // eslint-disable-next-line no-console console.warn(`Plugin API v${version} is not supported`); } } @@ -843,6 +847,7 @@ export function resetPluginApi() { } export function decorateCooked() { + // eslint-disable-next-line no-console console.warn( "`decorateCooked` has been removed. Use `getPluginApi(version).decorateCooked` instead" ); diff --git a/app/assets/javascripts/discourse/lib/theme-selector.js.es6 b/app/assets/javascripts/discourse/lib/theme-selector.js.es6 index 69a2eeb935d..60d61c20c53 100644 --- a/app/assets/javascripts/discourse/lib/theme-selector.js.es6 +++ b/app/assets/javascripts/discourse/lib/theme-selector.js.es6 @@ -4,6 +4,7 @@ import deprecated from "discourse-common/lib/deprecated"; const keySelector = "meta[name=discourse_theme_ids]"; export function currentThemeKey() { + // eslint-disable-next-line no-console if (console && console.warn && console.trace) { // TODO: Remove this code Jan 2019 deprecated( diff --git a/app/assets/javascripts/discourse/routes/preferences-about.js.es6 b/app/assets/javascripts/discourse/routes/preferences-about.js.es6 index 1ec3ac2ceef..7a3d41557e1 100644 --- a/app/assets/javascripts/discourse/routes/preferences-about.js.es6 +++ b/app/assets/javascripts/discourse/routes/preferences-about.js.es6 @@ -37,8 +37,7 @@ export default RestrictedUserRoute.extend({ }, function() { // model failed to save - controller.set("saving", false); - alert(I18n.t("generic_error")); + bootbox.alert(I18n.t("generic_error")); } ); } diff --git a/app/assets/javascripts/discourse/routes/topic-from-params.js.es6 b/app/assets/javascripts/discourse/routes/topic-from-params.js.es6 index 7f74dbd7bdf..d3ec450f21e 100644 --- a/app/assets/javascripts/discourse/routes/topic-from-params.js.es6 +++ b/app/assets/javascripts/discourse/routes/topic-from-params.js.es6 @@ -75,6 +75,7 @@ export default Discourse.Route.extend({ }) .catch(e => { if (!Ember.testing) { + // eslint-disable-next-line no-console console.log("Could not view topic", e); } }); diff --git a/app/assets/javascripts/discourse/widgets/glue.js.es6 b/app/assets/javascripts/discourse/widgets/glue.js.es6 index 76b9602509a..24aa1ac6af2 100644 --- a/app/assets/javascripts/discourse/widgets/glue.js.es6 +++ b/app/assets/javascripts/discourse/widgets/glue.js.es6 @@ -14,6 +14,7 @@ export default class WidgetGlue { this._widgetClass = queryRegistry(name) || this.register.lookupFactory(`widget:${name}`); if (!this._widgetClass) { + // eslint-disable-next-line no-console console.error(`Error: Could not find widget: ${name}`); } } diff --git a/app/assets/javascripts/discourse/widgets/hbs-compiler.js.es6 b/app/assets/javascripts/discourse/widgets/hbs-compiler.js.es6 index d6cc3412753..71bd31e6f1f 100644 --- a/app/assets/javascripts/discourse/widgets/hbs-compiler.js.es6 +++ b/app/assets/javascripts/discourse/widgets/hbs-compiler.js.es6 @@ -1,3 +1,4 @@ export default function hbs() { + // eslint-disable-next-line no-console console.log("Templates should be precompiled server side"); } diff --git a/app/assets/javascripts/discourse/widgets/widget.js.es6 b/app/assets/javascripts/discourse/widgets/widget.js.es6 index 88b6b9a5853..9b55573991f 100644 --- a/app/assets/javascripts/discourse/widgets/widget.js.es6 +++ b/app/assets/javascripts/discourse/widgets/widget.js.es6 @@ -133,6 +133,7 @@ export function createWidget(name, opts) { export function reopenWidget(name, opts) { let existing = _registry[name]; if (!existing) { + // eslint-disable-next-line no-console console.error(`Could not find widget ${name} in registry`); return; } @@ -205,9 +206,7 @@ export default class Widget { return {}; } - destroy() { - console.log("destroy called"); - } + destroy() {} render(prev) { const { dirtyKeys } = this; @@ -268,6 +267,7 @@ export default class Widget { if (!WidgetClass) { if (!this.register) { + // eslint-disable-next-line no-console console.error("couldn't find register"); return; } @@ -310,6 +310,7 @@ export default class Widget { if (view) { const method = view.get(name); if (!method) { + // eslint-disable-next-line no-console console.warn(`${name} not found`); return; } diff --git a/app/assets/javascripts/preload-application-data.js.no-module.es6 b/app/assets/javascripts/preload-application-data.js.no-module.es6 index 7291d919502..5f3755050f7 100644 --- a/app/assets/javascripts/preload-application-data.js.no-module.es6 +++ b/app/assets/javascripts/preload-application-data.js.no-module.es6 @@ -47,6 +47,7 @@ } if (Discourse.Environment === "development") { + /* eslint-disable no-console */ if (e) { if (e.message || e.stack) { console.log(e.message); @@ -57,6 +58,7 @@ } else { console.log("A promise failed but was not caught."); } + /* eslint-enable no-console */ } window.onerror(e && e.message, null, null, null, e);