Skip to content

Commit

Permalink
style: fix unicorn/prefer-negative-index
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL committed Jan 16, 2024
1 parent 4be33f0 commit 9410ae0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"unicorn/prefer-dom-node-text-content": 1,
"unicorn/prefer-logical-operator-over-ternary": 1,
"unicorn/prefer-module": 0,
"unicorn/prefer-negative-index": 1,
"unicorn/prefer-node-protocol": 0,
"unicorn/prefer-number-properties": 0,
"unicorn/prefer-object-from-entries": 1,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/magireco/announcements.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async (ctx) => {
if (!~listData.headers['content-type'].indexOf('application/json')) {
ctx.throw(403, 'Server not allow to get announcement.');
}
const data = listData.data.slice(listData.data.length - 50);
const data = listData.data.slice(-50);
ctx.state.data = {
title: '魔法纪录日服 - 游戏公告',
link,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/magireco/event_banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async (ctx) => {
if (!~listData.headers['content-type'].indexOf('application/json')) {
ctx.throw(403, 'Server not allow to get announcement.');
}
const data = listData.data.slice(listData.data.length - 50);
const data = listData.data.slice(-50);
ctx.state.data = {
title: '魔法纪录日服 - 游戏横幅',
link,
Expand Down
2 changes: 1 addition & 1 deletion lib/v2/dongqiudi/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: `${teamName} 比赛结果`,
link,
item: out.slice(out.length - 10, out.length),
item: out.slice(-10, out.length),
};
};
2 changes: 1 addition & 1 deletion lib/v2/hdu/cs/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getSingleRecord = async () => {
.map((index, item) => {
item = $(item);
const dateTxt = item.find('.date').text();
const date = dateTxt.slice(1, dateTxt.length - 1);
const date = dateTxt.slice(1, -1);
return {
title: item.find('a').text(),
pubDate: parseDate(date),
Expand Down
2 changes: 1 addition & 1 deletion lib/v2/hdu/cs/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getSingleRecord = async () => {
.map((index, item) => {
item = $(item);
const dateTxt = item.find('.date').text();
const date = dateTxt.slice(1, dateTxt.length - 1);
const date = dateTxt.slice(1, -1);
return {
title: item.find('a').text(),
pubDate: parseDate(date),
Expand Down
10 changes: 5 additions & 5 deletions lib/v2/phoronix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports = async (ctx) => {
const authorSelector = $('.author > a');
// the last 2 are the category and comments
const author = authorSelector
.slice(0, authorSelector.length - 2)
.slice(0, -2)
.toArray()
.map((e) => $(e).text());
const category = [];
Expand All @@ -154,7 +154,7 @@ module.exports = async (ctx) => {
// the text next to the category is the date
let pubDateReadable = categorySelector.length && categorySelector[0].nextSibling?.nodeValue;
if (pubDateReadable) {
pubDateReadable = pubDateReadable.replace(/on|at|\./g, '').trim();
pubDateReadable = pubDateReadable.replaceAll(/on|at|\./g, '').trim();
if (/\d{4}$/.test(pubDateReadable)) {
// Only date, no time
// Michael Larabel lives in Indiana, USA, so we assume TZ=America/Indiana/Indianapolis
Expand Down Expand Up @@ -207,10 +207,10 @@ module.exports = async (ctx) => {
const topicImage = images.first();
if (topicImage.attr('src')?.startsWith('/assets/categories/')) {
const topicImageContainer = topicImage.parent();
if (!topicImageContainer.text().trim()) {
topicImageContainer.remove();
} else {
if (topicImageContainer.text().trim()) {
topicImage.remove();
} else {
topicImageContainer.remove();
}
}
// High-res images
Expand Down
2 changes: 1 addition & 1 deletion lib/v2/sdu/wh/jwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = async (ctx) => {
const title = item.text();
const { description, author: exactAuthor, exactDate } = await ctx.cache.tryGet(link, () => extractor(link, ctx));
const author = exactAuthor ?? '教务处';
const pubDate = exactDate ?? timezone(parseDate(dateText.slice(1, dateText.length - 1), 'YYYY-MM-DD'), +8);
const pubDate = exactDate ?? timezone(parseDate(dateText.slice(1, -1), 'YYYY-MM-DD'), +8);
return {
title,
link,
Expand Down

0 comments on commit 9410ae0

Please sign in to comment.