Skip to content

Commit

Permalink
eslint: fix no-return-assign (wikimedia-gadgets#2103)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NovemLinguae authored Dec 10, 2024
1 parent bc79c32 commit fb98dfc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion modules/twinkletag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '.';
Expand Down
9 changes: 8 additions & 1 deletion tests/twinkletag.test.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit fb98dfc

Please sign in to comment.