I get eslint error and how to I fix it?
const filter = state.playListSetData.filter(item => {
// 若兩相符合,抓播放設定底下的其他資料
if (item.uuid === payload[i].playerList[j].uuid) {
return item;
}
});
for (let i = 0; i < payload.length; i += 1) {
// i表示數量window //遍歷每個channel
// window底下的播放清單
for (let j = 0; j < payload[i].playerList.length; j += 1) {
// 遍歷每個window底下的播放清單
// 比對window的播放清單跟播放設定的播放清單
const filter = state.playListSetData.filter(item => {
// 若兩相符合,抓播放設定底下的其他資料
if (item.uuid === payload[i].playerList[j].uuid) {
return item;
}
});
// 塞入所有window1的檔案
if (i === 0) {
// 遍歷視窗1過濾播放清單底下的檔案
for (let x = 0; x < filter[0].player_items.length; x += 1) {
state.playList1.push(filter[0].player_items[x].file);
}
} else if (i === 1) {
// 塞入所有window2的檔案
// 遍歷視窗2過濾播放清單底下的檔案
for (let x = 0; x < filter[0].player_items.length; x += 1) {
state.playList2.push(filter[0].player_items[x].file);
}
} else if (i === 2) {
// 塞入所有window3的檔案
// 遍歷視窗3過濾播放清單底下的檔案
for (let x = 0; x < filter[0].player_items.length; x += 1) {
state.playList3.push(filter[0].player_items[x].file);
}
} else {
// 塞入所有window4的檔案
// 遍歷視窗4過濾播放清單底下的檔案
for (let x = 0; x < filter[0].player_items.length; x += 1) {
state.playList4.push(filter[0].player_items[x].file);
}
}
}
}
const filter = state.playListSetData.filter(item => {
// 若兩相符合,抓播放設定底下的其他資料
if (item.uuid === payload[i].playerList[j].uuid) {
return item;
}
return false;
});
if you return something for some cases, your linter wants you to explicitly return something for all cases. return undefined
I guess is closer to what it was doing before but it is all the same for filter
or simply
const filter = state.playListSetData.filter(item => {
// 若兩相符合,抓播放設定底下的其他資料
return item.uuid === payload[i].playerList[j].uuid;
});
filter only cares if it is truthy, and doesn't really use the value of item, and since you are accessing properties, it looks like it is always truthy, so just return true.