Skip to content

Commit 1d37c36

Browse files
committed
Fix eslint
1 parent 435d31a commit 1d37c36

34 files changed

+190
-167
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"start": "NODE_ENV=production node app.js",
99
"dev": "tsc-watch --onSuccess \"node ./dist/src/index.js\"",
10-
"eslint": "eslint --fix",
10+
"eslint": "eslint --fix --cache",
1111
"tsc": "tsc --noEmit -p tsconfig.json",
1212
"lint": "yarn tsc && yarn eslint",
1313
"test": "cross-env NODE_ENV=test yarn lint && yarn test:unit",

src/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const settings: { readonly setPresence: boolean; readonly config: ClientConfig }
5252
};
5353

5454
client.on('ready', () => {
55-
console.log(`Logged in as ${client.user?.tag}!`);
55+
console.log(`Logged in as ${client.user?.tag!}!`);
5656
});
5757

5858
// eslint-disable-next-line functional/prefer-readonly-type
@@ -196,9 +196,9 @@ async function init() {
196196
{
197197
const TYPE_OF_WEB_GUILD_ID = '440163731704643589';
198198
const guild = await client.guilds.fetch(TYPE_OF_WEB_GUILD_ID);
199-
updateRoles(guild);
199+
void updateRoles(guild);
200200
setInterval(() => {
201-
updateRoles(guild);
201+
void updateRoles(guild);
202202
}, 1000 * 60 * 60 * 24 * 1);
203203
}
204204

src/commands/co.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import co from './co';
2-
import { getMessageMock } from '../../test/mocks';
31
import { expect } from 'chai';
4-
import * as Discord from 'discord.js';
2+
import type * as Discord from 'discord.js';
3+
4+
import { getMessageMock } from '../../test/mocks';
5+
6+
import co from './co';
57

68
describe('co', () => {
79
it('it should send a file', async () => {
8-
const msg = getMessageMock('msg');
10+
const msg = getMessageMock('msg', {});
911

1012
await co.execute(msg as unknown as Discord.Message, []);
1113

12-
await expect(msg.channel.send).to.have.been.calledOnce;
14+
expect(msg.channel.send).to.have.been.calledOnce;
1315
});
1416
});

src/commands/co.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from '../types';
1+
import type { Command } from '../types';
22

33
const co: Command = {
44
name: 'co',

src/commands/execute.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
23
import 'mocha';
34
import * as execute from './execute';
45

@@ -147,6 +148,8 @@ describe('Command: execute', () => {
147148
}
148149
`,
149150
];
151+
152+
// eslint-disable-next-line functional/no-loop-statement
150153
for (const code of dangerous) {
151154
await expect(execute.executeCode(code, 'js')).to.eventually.be.rejected;
152155
}

src/commands/karma.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
3+
/* eslint-disable functional/no-this-expression */
14
import { expect } from 'chai';
25
import type * as Discord from 'discord.js';
36
import Sinon from 'sinon';
4-
import * as Db from '../db';
57

68
import { getMessageMock, getMemberMock } from '../../test/mocks';
9+
import * as Db from '../db';
710

811
import { addKarma, KARMA_REGEX } from './karma';
912

src/commands/karma.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const addKarma: Command = {
5656

5757
const messages = membersKarma.map(({ value, _id }) => {
5858
const member = membersToReward.find((m) => m.id === _id);
59-
return `${msg.author.toString()} podziękował(a) ${member?.toString()}! ${member?.toString()} ma ${getKarmaDescription(
59+
return `${msg.author.toString()} podziękował(a) ${member?.toString()!}! ${member?.toString()!} ma ${getKarmaDescription(
6060
value,
6161
)}`;
6262
});

src/commands/kocopoly.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Command, CommandWithArgs } from '../types';
2-
31
import Fsp from 'fs/promises';
42
import Path from 'path';
5-
import { getRandomKocopolyAnswers } from './kocopoly/kocopolyUtils';
3+
4+
import type { Command, CommandWithArgs } from '../types';
65
import { capitalizeFirst, wait } from '../utils';
76

7+
import { getRandomKocopolyAnswers } from './kocopoly/kocopolyUtils';
8+
89
const COOLDOWN = 20;
910
const KOCOPOLY_DELAY = 1500;
1011

@@ -16,7 +17,7 @@ const kocopolyExecute =
1617

1718
const kocopolyJson = JSON.parse(
1819
await Fsp.readFile(Path.join(__dirname, '..', kocopolyFilename), 'utf-8'),
19-
) as string[];
20+
) as readonly string[];
2021

2122
const messages = await getRandomKocopolyAnswers(username, question, kocopolyJson, kocopolyName);
2223

src/commands/kocopoly/kocopolyUtils.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Configuration, OpenAIApi } from 'openai';
21
import Natural from 'natural';
2+
import { Configuration, OpenAIApi } from 'openai';
33

44
const configuration = new Configuration({
55
apiKey: process.env.OPENAI_API_KEY,
@@ -15,13 +15,13 @@ const BANNED_PATTERNS = /[`\[\]{}\(\)]|http/g;
1515
const getRandomInt = (len: number) => Math.floor(Math.random() * len);
1616

1717
interface KocopolyGenerator {
18-
(username: string, question: string, kocopolyJson: string[], kocopolyName: string): Promise<
19-
string[]
20-
>;
18+
(username: string, question: string, kocopolyJson: readonly string[], kocopolyName: string):
19+
| readonly string[]
20+
| Promise<readonly string[]>;
2121
}
2222

2323
// random
24-
export const getRandomKocopolyAnswers: KocopolyGenerator = async (
24+
export const getRandomKocopolyAnswers: KocopolyGenerator = (
2525
_username,
2626
question,
2727
kocopolyJson,
@@ -43,6 +43,7 @@ export const getRandomKocopolyAnswers: KocopolyGenerator = async (
4343
const lines = [];
4444
let idx = initialIndex === -1 ? getRandomInt(g.length) : initialIndex;
4545

46+
// eslint-disable-next-line functional/no-loop-statement
4647
for (let i = 0; i < numberOfLines; ++i) {
4748
lines.push(g[idx]);
4849

@@ -63,7 +64,7 @@ export const getKocopolyAnswerFromOpenAI: KocopolyGenerator = async (
6364
kocopolyJson,
6465
kocopolyName,
6566
) => {
66-
const prompt = await generateKocopolyPrompt(username, question, kocopolyJson, kocopolyName);
67+
const prompt = generateKocopolyPrompt(username, question, kocopolyJson, kocopolyName);
6768

6869
const engine = 'text-davinci-001';
6970
// const engine = 'text-babbage-001';
@@ -94,14 +95,15 @@ export const getKocopolyAnswerFromOpenAI: KocopolyGenerator = async (
9495

9596
const getRandomIndices = (num: number, max: number) => {
9697
const set = new Set<number>();
98+
// eslint-disable-next-line functional/no-loop-statement
9799
while (set.size < num) set.add(getRandomInt(max));
98100
return [...set];
99101
};
100102

101-
const generateKocopolyPrompt = async (
103+
const generateKocopolyPrompt = (
102104
username: string,
103105
question: string,
104-
kocopolyJson: string[],
106+
kocopolyJson: readonly string[],
105107
kocopolyName: string,
106108
) => {
107109
const indices = getRandomIndices(100, kocopolyJson.length);

src/commands/markdown.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import Discord from 'discord.js';
2-
import { Command } from '../types';
1+
import type Discord from 'discord.js';
2+
3+
import type { Command } from '../types';
34

45
const markdownCodes = [
56
'*tekst*',
@@ -15,7 +16,7 @@ const markdownCodes = [
1516

1617
const sourceExample = ['\\`\\`\\`js (html, css, json, cp, md, py, xml etc.)', 'kod', '\\`\\`\\`'];
1718

18-
function codesToInstruction(codes: string[]) {
19+
function codesToInstruction(codes: readonly string[]) {
1920
const maxLength = Math.max(...codes.map((x) => x.length));
2021

2122
return codes.map((code) => {

src/commands/mongodb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from '../types';
1+
import type { Command } from '../types';
22

33
const mongodb: Command = {
44
name: 'mongodb',

src/commands/mydevil.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import Discord from 'discord.js';
2-
import { Command } from '../types';
1+
import type Discord from 'discord.js';
2+
3+
import type { Command } from '../types';
34

45
const mydevil: Command = {
56
name: 'mydevil',

src/commands/odpowiedz.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from '../types';
1+
import type { Command } from '../types';
22
import { randomizeArray } from '../utils';
33
const ANSWERS = [
44
'Mój wywiad donosi: NIE',

src/commands/prs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from '../types';
1+
import type { Command } from '../types';
22

33
const formatter = new Intl.ListFormat('pl', { style: 'long', type: 'conjunction' });
44

src/commands/prune.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
12
import { expect } from 'chai';
23
import type * as Discord from 'discord.js';
34
import Sinon from 'sinon';
@@ -7,16 +8,16 @@ import { getMessageMock } from '../../test/mocks';
78
import prune from './prune';
89

910
describe('prune', () => {
10-
it('should show an error when you try to delete less than 1 message', async () => {
11-
const msg = getMessageMock('msg');
11+
it('should show an error when you try to delete less than 1 message', () => {
12+
const msg = getMessageMock('msg', {});
1213

1314
return expect(
1415
prune.execute(msg as unknown as Discord.Message, ['0']),
1516
).to.be.eventually.rejectedWith('Musisz podać przynajmniej 1.');
1617
});
1718

18-
it('should show an error when you try to delete more than 10 messages', async () => {
19-
const msg = getMessageMock('msg');
19+
it('should show an error when you try to delete more than 10 messages', () => {
20+
const msg = getMessageMock('msg', {});
2021

2122
return expect(
2223
prune.execute(msg as unknown as Discord.Message, ['11']),
@@ -25,16 +26,16 @@ describe('prune', () => {
2526
);
2627
});
2728

28-
it('should show an error when you try to delete adsads messages', async () => {
29-
const msg = getMessageMock('msg');
29+
it('should show an error when you try to delete adsads messages', () => {
30+
const msg = getMessageMock('msg', {});
3031

3132
return expect(
3233
prune.execute(msg as unknown as Discord.Message, ['adsads']),
3334
).to.be.eventually.rejectedWith('Parametr musi być liczbą wiadomości.');
3435
});
3536

3637
it('should fetch messages and delete them', async () => {
37-
const msg = getMessageMock('msg');
38+
const msg = getMessageMock('msg', {});
3839
const memberMock = {
3940
hasPermission: Sinon.spy(),
4041
};
@@ -44,18 +45,17 @@ describe('prune', () => {
4445
msg.guild.members.cache.get.returns(memberMock);
4546

4647
await expect(prune.execute(msg as unknown as Discord.Message, ['2'])).to.be.fulfilled;
47-
await expect(msg.channel.messages.fetch).to.have.been.calledOnceWithExactly({ limit: 2 });
48-
await expect(msg.channel.bulkDelete).to.have.been.calledOnceWithExactly(messagesCollectionMock);
48+
expect(msg.channel.messages.fetch).to.have.been.calledOnceWithExactly({ limit: 2 });
49+
expect(msg.channel.bulkDelete).to.have.been.calledOnceWithExactly(messagesCollectionMock);
4950
});
5051

5152
it('should delete itself', async () => {
52-
const msg = getMessageMock('msg');
53-
// tslint:disable-next-line: no-any
53+
const msg = getMessageMock('msg', {});
5454
const messagesCollectionMock = { clear: Sinon.spy() } as any;
5555
msg.channel.messages.fetch.resolves(messagesCollectionMock);
5656

5757
await prune.execute(msg as unknown as Discord.Message, ['2']);
5858

59-
await expect(msg.delete).to.have.been.calledOnce;
59+
expect(msg.delete).to.have.been.calledOnce;
6060
});
6161
});

src/commands/quiz.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Command } from '../types';
21
import fetch from 'node-fetch';
2+
3+
import type { Command } from '../types';
34
import { randomizeArray } from '../utils';
45

56
const MAX_QUESTIONS = 10;
@@ -73,18 +74,18 @@ const prepareUrl = (category: string, level: string) => {
7374
export default quiz;
7475

7576
interface DevFAQResponse {
76-
data: DevFAQ[];
77-
meta: {
78-
total: number;
77+
readonly data: readonly DevFAQ[];
78+
readonly meta: {
79+
readonly total: number;
7980
};
8081
}
8182

8283
interface DevFAQ {
83-
id: number;
84-
question: string;
85-
_categoryId: string;
86-
_levelId: string;
87-
_statusId: string;
88-
acceptedAt: string;
89-
currentUserVotedOn: boolean;
84+
readonly id: number;
85+
readonly question: string;
86+
readonly _categoryId: string;
87+
readonly _levelId: string;
88+
readonly _statusId: string;
89+
readonly acceptedAt: string;
90+
readonly currentUserVotedOn: boolean;
9091
}

src/commands/reflink.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from 'chai';
2+
23
import { helionReflink, xKomReflink } from './reflink';
34

45
describe('reflink', () => {

src/commands/reflink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const xKomReflink = (url: string) => {
2323

2424
const suffix = `?partnerid=${X_KOM_PARTNER_ID}&sm12=NDY=&ts=1641758054&token=6ab7b9cde43c838f9e76042a3b8bfdcd`;
2525
const mainLink = url.split('#')[0];
26-
return mainLink + suffix + '&' + mainLink.length;
26+
return mainLink + suffix + '&' + mainLink.length.toString();
2727
};
2828

2929
export const isHelionReflink = (url: string) => {
@@ -55,7 +55,7 @@ export const myDevilReflink = () => {
5555
return `https://www.mydevil.net/pp/9UVOSJRZIV`;
5656
};
5757

58-
export const messageToReflinks = (message: string): string[] => {
58+
export const messageToReflinks = (message: string): readonly string[] => {
5959
const maybeLinks = message.match(/https?:\/\/[^\s]+/g);
6060
if (!maybeLinks) {
6161
return [];

src/commands/regulamin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import Discord from 'discord.js';
2-
import { Command } from '../types';
1+
import type Discord from 'discord.js';
2+
3+
import type { Command } from '../types';
34

45
const regulamin: Command = {
56
name: 'regulamin',

src/commands/roll.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai';
22
import 'mocha';
3+
import type * as Discord from 'discord.js';
34

45
import { getMessageMock } from '../../test/mocks';
5-
import * as Discord from 'discord.js';
66

77
import roll, { parseDice, rollDices, instruction } from './roll';
88

@@ -49,14 +49,14 @@ describe('roll', () => {
4949
});
5050
describe('handleCommand', () => {
5151
it('should reply', async () => {
52-
const msg = getMessageMock('msg');
52+
const msg = getMessageMock('msg', {});
5353
await roll.execute(msg as unknown as Discord.Message, ['4d6']);
54-
await expect(msg.channel.send).to.have.been.calledOnce;
54+
expect(msg.channel.send).to.have.been.calledOnce;
5555
});
5656
it('reply instruction on fail', async () => {
57-
const msg = getMessageMock('msg');
57+
const msg = getMessageMock('msg', {});
5858
await roll.execute(msg as unknown as Discord.Message, ['3k5']);
59-
await expect(msg.channel.send).to.have.been.calledOnceWith(instruction);
59+
expect(msg.channel.send).to.have.been.calledOnceWith(instruction);
6060
});
6161
});
6262
});

src/commands/roll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command } from '../types';
1+
import type { Command } from '../types';
22

33
const MAX_COUNT = 20;
44
const MAX_DICE = 100;

0 commit comments

Comments
 (0)