From 2f1145726370b9210dc7ab2503193064feee7ef4 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 31 Aug 2020 15:39:10 -0400 Subject: [PATCH] REFACTOR: Use `Array.isArray` instead of `_.isArray` --- .eslintrc | 4 +++- app/assets/javascripts/admin/models/report.js | 2 +- .../javascripts/discourse/app/components/group-selector.js | 2 +- .../discourse/app/components/search-advanced-options.js | 6 +++--- app/assets/javascripts/discourse/app/lib/autocomplete.js | 2 +- app/assets/javascripts/discourse/app/lib/computed.js | 2 +- test/javascripts/components/keyboard-shortcuts-test.js | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 43564589375..2c52e6ffef0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,8 @@ "discourse-ember/global-ember": 2 }, "globals": { - "bootbox": "off" + "bootbox": "off", + "Mousetrap": "off", + "_": "off" } } diff --git a/app/assets/javascripts/admin/models/report.js b/app/assets/javascripts/admin/models/report.js index 8475a26a95b..508fb4d959c 100644 --- a/app/assets/javascripts/admin/models/report.js +++ b/app/assets/javascripts/admin/models/report.js @@ -492,7 +492,7 @@ Report.reopenClass({ const startDate = options.startDate || "start_date"; const endDate = options.endDate || "end_date"; - if (_.isArray(report[dataField])) { + if (Array.isArray(report[dataField])) { const startDateFormatted = moment .utc(report[startDate]) .locale("en") diff --git a/app/assets/javascripts/discourse/app/components/group-selector.js b/app/assets/javascripts/discourse/app/components/group-selector.js index e39aadecbc7..cac994054ae 100644 --- a/app/assets/javascripts/discourse/app/components/group-selector.js +++ b/app/assets/javascripts/discourse/app/components/group-selector.js @@ -27,7 +27,7 @@ export default Component.extend({ $(this.element.querySelector("input")).autocomplete({ debounced: true, allowAny: false, - items: _.isArray(groupNames) + items: Array.isArray(groupNames) ? groupNames : isEmpty(groupNames) ? [] diff --git a/app/assets/javascripts/discourse/app/components/search-advanced-options.js b/app/assets/javascripts/discourse/app/components/search-advanced-options.js index 365f7ed436e..ad44ac73b91 100644 --- a/app/assets/javascripts/discourse/app/components/search-advanced-options.js +++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.js @@ -275,7 +275,7 @@ export default Component.extend({ const group = this.get("searchedTerms.group"); if (match.length !== 0) { - const existingInput = _.isArray(group) ? group[0] : group; + const existingInput = Array.isArray(group) ? group[0] : group; const userInput = match[0].replace(REGEXP_GROUP_PREFIX, ""); if (existingInput !== userInput) { @@ -294,7 +294,7 @@ export default Component.extend({ const badge = this.get("searchedTerms.badge"); if (match.length !== 0) { - const existingInput = _.isArray(badge) ? badge[0] : badge; + const existingInput = Array.isArray(badge) ? badge[0] : badge; const userInput = match[0].replace(REGEXP_BADGE_PREFIX, ""); if (existingInput !== userInput) { @@ -317,7 +317,7 @@ export default Component.extend({ if (match.length !== 0) { const join_char = contain_all_tags ? "+" : ","; - const existingInput = _.isArray(tags) ? tags.join(join_char) : tags; + const existingInput = Array.isArray(tags) ? tags.join(join_char) : tags; const userInput = match[0].replace(REGEXP_TAGS_REPLACE, ""); if (existingInput !== userInput) { diff --git a/app/assets/javascripts/discourse/app/lib/autocomplete.js b/app/assets/javascripts/discourse/app/lib/autocomplete.js index 1b2a0b6100d..47cde9a4f87 100644 --- a/app/assets/javascripts/discourse/app/lib/autocomplete.js +++ b/app/assets/javascripts/discourse/app/lib/autocomplete.js @@ -113,7 +113,7 @@ export default function(options) { if (options.single) { inputSelectedItems = []; } - transformed = _.isArray(transformedItem) + transformed = Array.isArray(transformedItem) ? transformedItem : [transformedItem || item]; diff --git a/app/assets/javascripts/discourse/app/lib/computed.js b/app/assets/javascripts/discourse/app/lib/computed.js index 51292ae13a4..a625647e515 100644 --- a/app/assets/javascripts/discourse/app/lib/computed.js +++ b/app/assets/javascripts/discourse/app/lib/computed.js @@ -6,7 +6,7 @@ import { htmlSafe as htmlSafeTemplateHelper } from "@ember/template"; function addonFmt(str, formats) { let cachedFormats = formats; - if (!_.isArray(cachedFormats) || arguments.length > 2) { + if (!Array.isArray(cachedFormats) || arguments.length > 2) { cachedFormats = new Array(arguments.length - 1); for (let i = 1, l = arguments.length; i < l; i++) { diff --git a/test/javascripts/components/keyboard-shortcuts-test.js b/test/javascripts/components/keyboard-shortcuts-test.js index 025bec5ecf0..7e9c6f2783b 100644 --- a/test/javascripts/components/keyboard-shortcuts-test.js +++ b/test/javascripts/components/keyboard-shortcuts-test.js @@ -13,7 +13,7 @@ QUnit.module("lib:keyboard-shortcuts", { _bindings[binding] = callback; }.bind(this); - if (_.isArray(bindings)) { + if (Array.isArray(bindings)) { bindings.forEach(registerBinding, this); } else { registerBinding(bindings);