From fb98dfcb7ce10b9ef8ae515585844aa28bf430ac Mon Sep 17 00:00:00 2001 From: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com> Date: Tue, 10 Dec 2024 03:16:33 -0800 Subject: [PATCH] eslint: fix no-return-assign (#2103) * eslint: fix no-return-assign manual fix * use sum++ instead of ternary, easier to read * use .filter() instead of .reduce() * fix linter error * add test --- .eslintrc.json | 1 - modules/twinkletag.js | 2 +- tests/twinkletag.test.js | 9 ++++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4d69942fb..e3f7dd7bb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -54,7 +54,6 @@ "no-jquery/no-sizzle": "warn", "no-loop-func": "warn", "no-new": "warn", - "no-return-assign": "warn", "no-script-url": "warn", "no-unused-expressions": "warn", "no-use-before-define": "warn", diff --git a/modules/twinkletag.js b/modules/twinkletag.js index 2e7caea29..52ec8b969 100644 --- a/modules/twinkletag.js +++ b/modules/twinkletag.js @@ -2009,7 +2009,7 @@ Twinkle.tag.callbacks = { * @return {true|undefined} */ Twinkle.tag.checkIncompatible = function(incompatibleTags, tagsToCheck, extraMessage = null) { - const count = incompatibleTags.reduce((sum, tag) => sum += tagsToCheck.indexOf(tag) !== -1, 0); + const count = incompatibleTags.filter((tag) => tagsToCheck.includes(tag)).length; if (count > 1) { const incompatibleTagsString = '{{' + incompatibleTags.join('}}, {{') + '}}'; let message = 'Please select only one of: ' + incompatibleTagsString + '.'; diff --git a/tests/twinkletag.test.js b/tests/twinkletag.test.js index f890b1126..16f913d55 100644 --- a/tests/twinkletag.test.js +++ b/tests/twinkletag.test.js @@ -1,6 +1,13 @@ describe('modules/twinkletag', () => { describe('checkIncompatible', () => { - test('no conflicts', () => { + test('no conflicts, 0 tags to check', () => { + const incompatibleTags = ['Bad GIF', 'Bad JPEG', 'Bad SVG', 'Bad format']; + const tagsToCheck = []; + const expected = undefined; + expect(Twinkle.tag.checkIncompatible(incompatibleTags, tagsToCheck)).toBe(expected); + }); + + test('no conflicts, 1 tag to check', () => { const incompatibleTags = ['Bad GIF', 'Bad JPEG', 'Bad SVG', 'Bad format']; const tagsToCheck = ['Better source requested']; const expected = undefined;