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) => {

0 commit comments

Comments
 (0)