Skip to content

Commit 16938da

Browse files
authored
chore: improve linting (#7244)
1 parent ff3a8b8 commit 16938da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+517
-430
lines changed

.vscode/settings.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"eslint.workingDirectories": [{ "pattern": "./packages/*" }]
2+
"eslint.workingDirectories": [{ "pattern": "./packages/*" }],
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true,
5+
"editor.codeActionsOnSave": {
6+
"source.fixAll": true,
7+
"source.organizeImports": false
8+
}
39
}

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
},
4040
"homepage": "https://discord.js.org",
4141
"devDependencies": {
42-
"@commitlint/cli": "^16.0.1",
42+
"@commitlint/cli": "^16.0.2",
4343
"@commitlint/config-angular": "^16.0.0",
4444
"@favware/npm-deprecate": "^1.0.4",
4545
"conventional-changelog-cli": "^2.2.2",
4646
"husky": "^7.0.4",
4747
"lint-staged": "^12.1.7",
4848
"prettier": "^2.5.1",
49-
"turbo": "^1.0.24"
49+
"turbo": "1.0.24"
5050
},
5151
"engines": {
5252
"node": ">=16.9.0"
@@ -70,7 +70,9 @@
7070
"dependsOn": [
7171
"^build"
7272
],
73-
"outputs": []
73+
"outputs": [
74+
"coverage/**"
75+
]
7476
},
7577
"lint": {
7678
"dependsOn": [

packages/builders/.eslintrc.json

-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@
88
"ignorePatterns": ["**/dist/*"],
99
"env": {
1010
"jest": true
11-
},
12-
"rules": {
13-
"no-redeclare": 0,
14-
"@typescript-eslint/naming-convention": 0
1511
}
1612
}

packages/builders/.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# Autogenerated
22
CHANGELOG.md
3+
.turbo
4+
dist/
5+
docs/**/*
6+
!docs/index.yml
7+
!docs/README.md
8+
coverage/

packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ describe('Slash Commands', () => {
178178
expect(() =>
179179
getBuilder().addStringOption(
180180
// @ts-expect-error Checking if check works JS-side too
181-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
181+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
182182
getStringOption().setAutocomplete(true).addChoice('Fancy Pants', 'fp_1'),
183183
),
184184
).toThrowError();
185185

186186
expect(() =>
187187
getBuilder().addStringOption(
188-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
188+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
189189
getStringOption()
190190
.setAutocomplete(true)
191191
// @ts-expect-error Checking if check works JS-side too
@@ -200,7 +200,7 @@ describe('Slash Commands', () => {
200200
expect(() =>
201201
getBuilder().addStringOption(
202202
// @ts-expect-error Checking if check works JS-side too
203-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
203+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
204204
getStringOption().addChoice('Fancy Pants', 'fp_1').setAutocomplete(true),
205205
),
206206
).toThrowError();
@@ -384,6 +384,7 @@ describe('Slash Commands', () => {
384384
test('GIVEN builder with a subcommand that tries to add an invalid result THEN throw error', () => {
385385
expect(() =>
386386
// @ts-expect-error Checking if check works JS-side too
387+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
387388
getNamedBuilder().addSubcommand(getSubcommand()).addInteger(getInteger()),
388389
).toThrowError();
389390
});

packages/builders/package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"scripts": {
66
"build": "tsup",
77
"test": "jest --pass-with-no-tests",
8-
"lint": "eslint src --ext mjs,js,ts",
9-
"lint:fix": "eslint src --ext mjs,js,ts --fix",
10-
"format": "prettier --write .",
8+
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
9+
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
1110
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && node scripts/docs.mjs",
1211
"prepublishOnly": "yarn build && yarn lint && yarn test",
1312
"changelog": "git cliff --prepend ./CHANGELOG.md -l -c ../../cliff.toml -r ../../ --include-path './*'"
@@ -61,16 +60,16 @@
6160
"devDependencies": {
6261
"@babel/core": "^7.16.5",
6362
"@babel/plugin-proposal-decorators": "^7.16.5",
64-
"@babel/preset-env": "^7.16.5",
63+
"@babel/preset-env": "^7.16.8",
6564
"@babel/preset-typescript": "^7.16.5",
6665
"@discordjs/ts-docgen": "^0.3.4",
6766
"@types/jest": "^27.0.3",
6867
"@types/node": "^16.11.6",
69-
"@typescript-eslint/eslint-plugin": "^5.9.0",
70-
"@typescript-eslint/parser": "^5.9.0",
68+
"@typescript-eslint/eslint-plugin": "^5.9.1",
69+
"@typescript-eslint/parser": "^5.9.1",
7170
"babel-plugin-transform-typescript-metadata": "^0.3.2",
7271
"eslint": "^8.5.0",
73-
"eslint-config-marine": "^9.1.0",
72+
"eslint-config-marine": "^9.3.2",
7473
"eslint-config-prettier": "^8.3.0",
7574
"eslint-plugin-prettier": "^4.0.0",
7675
"jest": "^27.4.7",

packages/builders/src/interactions/contextMenuCommands/Assertions.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ import { z } from 'zod';
22
import { ApplicationCommandType } from 'discord-api-types/v9';
33
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder';
44

5-
export function validateRequiredParameters(name: string, type: number) {
6-
// Assert name matches all conditions
7-
validateName(name);
8-
9-
// Assert type is valid
10-
validateType(type);
11-
}
12-
135
const namePredicate = z
146
.string()
157
.min(1)
168
.max(32)
179
.regex(/^( *[\p{L}\p{N}_-]+ *)+$/u);
1810

11+
const typePredicate = z.union([z.literal(ApplicationCommandType.User), z.literal(ApplicationCommandType.Message)]);
12+
13+
const booleanPredicate = z.boolean();
14+
15+
export function validateDefaultPermission(value: unknown): asserts value is boolean {
16+
booleanPredicate.parse(value);
17+
}
18+
1919
export function validateName(name: unknown): asserts name is string {
2020
namePredicate.parse(name);
2121
}
2222

23-
const typePredicate = z.union([z.literal(ApplicationCommandType.User), z.literal(ApplicationCommandType.Message)]);
24-
2523
export function validateType(type: unknown): asserts type is ContextMenuCommandType {
2624
typePredicate.parse(type);
2725
}
2826

29-
const booleanPredicate = z.boolean();
27+
export function validateRequiredParameters(name: string, type: number) {
28+
// Assert name matches all conditions
29+
validateName(name);
3030

31-
export function validateDefaultPermission(value: unknown): asserts value is boolean {
32-
booleanPredicate.parse(value);
31+
// Assert type is valid
32+
validateType(type);
3333
}

packages/builders/src/interactions/slashCommands/Assertions.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@ import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOp
55
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
66
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
77

8-
export function validateRequiredParameters(
9-
name: string,
10-
description: string,
11-
options: ToAPIApplicationCommandOptions[],
12-
) {
13-
// Assert name matches all conditions
14-
validateName(name);
15-
16-
// Assert description conditions
17-
validateDescription(description);
18-
19-
// Assert options conditions
20-
validateMaxOptionsLength(options);
21-
}
22-
238
const namePredicate = z
249
.string()
2510
.min(1)
@@ -36,6 +21,27 @@ export function validateDescription(description: unknown): asserts description i
3621
descriptionPredicate.parse(description);
3722
}
3823

24+
const maxArrayLengthPredicate = z.unknown().array().max(25);
25+
26+
export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
27+
maxArrayLengthPredicate.parse(options);
28+
}
29+
30+
export function validateRequiredParameters(
31+
name: string,
32+
description: string,
33+
options: ToAPIApplicationCommandOptions[],
34+
) {
35+
// Assert name matches all conditions
36+
validateName(name);
37+
38+
// Assert description conditions
39+
validateDescription(description);
40+
41+
// Assert options conditions
42+
validateMaxOptionsLength(options);
43+
}
44+
3945
const booleanPredicate = z.boolean();
4046

4147
export function validateDefaultPermission(value: unknown): asserts value is boolean {
@@ -46,12 +52,6 @@ export function validateRequired(required: unknown): asserts required is boolean
4652
booleanPredicate.parse(required);
4753
}
4854

49-
const maxArrayLengthPredicate = z.unknown().array().max(25);
50-
51-
export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
52-
maxArrayLengthPredicate.parse(options);
53-
}
54-
5555
export function validateMaxChoicesLength(choices: APIApplicationCommandOptionChoice[]) {
5656
maxArrayLengthPredicate.parse(choices);
5757
}

packages/builders/src/interactions/slashCommands/SlashCommandBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ export interface SlashCommandOptionsOnlyBuilder
133133
Pick<SlashCommandBuilder, 'toJSON'> {}
134134

135135
export interface ToAPIApplicationCommandOptions {
136-
toJSON(): APIApplicationCommandOption;
136+
toJSON: () => APIApplicationCommandOption;
137137
}

packages/builders/src/interactions/slashCommands/SlashCommandSubcommands.ts

+2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationComma
4848
validateMaxOptionsLength(options);
4949

5050
// Get the final result
51+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
5152
const result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;
5253

54+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
5355
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
5456

5557
// Push it

packages/collection/.eslintrc.json

-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@
88
"ignorePatterns": ["**/dist/*"],
99
"env": {
1010
"jest": true
11-
},
12-
"rules": {
13-
"no-redeclare": 0,
14-
"@typescript-eslint/naming-convention": 0
1511
}
1612
}

packages/collection/.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# Autogenerated
22
CHANGELOG.md
3+
.turbo
4+
dist/
5+
docs/**/*
6+
!docs/index.yml
7+
!docs/README.md
8+
coverage/

packages/collection/package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"scripts": {
66
"test": "jest --pass-with-no-tests",
77
"build": "tsup",
8-
"lint": "eslint src --ext mjs,js,ts",
9-
"lint:fix": "eslint src --ext mjs,js,ts --fix",
10-
"format": "prettier --write .",
8+
"lint": "prettier --check . && eslint src __tests__ --ext mjs,js,ts",
9+
"format": "prettier --write . && eslint src __tests__ --ext mjs,js,ts --fix",
1110
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && node scripts/docs.mjs",
1211
"prepublishOnly": "yarn build && yarn lint && yarn test",
1312
"changelog": "git cliff --prepend ./CHANGELOG.md -l -c ../../cliff.toml -r ../../ --include-path './*'"
@@ -49,15 +48,15 @@
4948
"homepage": "https://discord.js.org",
5049
"devDependencies": {
5150
"@babel/core": "^7.16.5",
52-
"@babel/preset-env": "^7.16.5",
51+
"@babel/preset-env": "^7.16.8",
5352
"@babel/preset-typescript": "^7.16.5",
5453
"@discordjs/ts-docgen": "^0.3.4",
5554
"@types/jest": "^27.0.3",
5655
"@types/node": "^16.11.6",
57-
"@typescript-eslint/eslint-plugin": "^5.9.0",
58-
"@typescript-eslint/parser": "^5.9.0",
56+
"@typescript-eslint/eslint-plugin": "^5.9.1",
57+
"@typescript-eslint/parser": "^5.9.1",
5958
"eslint": "^8.5.0",
60-
"eslint-config-marine": "^9.1.0",
59+
"eslint-config-marine": "^9.3.2",
6160
"eslint-config-prettier": "^8.3.0",
6261
"eslint-plugin-prettier": "^4.0.0",
6362
"jest": "^27.4.7",

packages/collection/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ export class Collection<K, V> extends Map<K, V> {
7373
public first(): V | undefined;
7474
public first(amount: number): V[];
7575
public first(amount?: number): V | V[] | undefined {
76+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
7677
if (typeof amount === 'undefined') return this.values().next().value;
7778
if (amount < 0) return this.last(amount * -1);
7879
amount = Math.min(this.size, amount);
7980
const iter = this.values();
81+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
8082
return Array.from({ length: amount }, (): V => iter.next().value);
8183
}
8284

@@ -91,10 +93,12 @@ export class Collection<K, V> extends Map<K, V> {
9193
public firstKey(): K | undefined;
9294
public firstKey(amount: number): K[];
9395
public firstKey(amount?: number): K | K[] | undefined {
96+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
9497
if (typeof amount === 'undefined') return this.keys().next().value;
9598
if (amount < 0) return this.lastKey(amount * -1);
9699
amount = Math.min(this.size, amount);
97100
const iter = this.keys();
101+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
98102
return Array.from({ length: amount }, (): K => iter.next().value);
99103
}
100104

@@ -398,6 +402,7 @@ export class Collection<K, V> extends Map<K, V> {
398402
if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg);
399403
const iter = this.entries();
400404
return Array.from({ length: this.size }, (): T => {
405+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
401406
const [key, value] = iter.next().value;
402407
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
403408
return fn(value, key, this);

packages/discord.js/.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# Autogenerated
22
CHANGELOG.md
3+
.turbo
4+
dist/
5+
docs/**/*
6+
!docs/index.yml
7+
!docs/README.md
8+
coverage/

packages/discord.js/package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
"version": "14.0.0-dev",
44
"description": "A powerful library for interacting with the Discord API",
55
"scripts": {
6-
"test": "yarn docs:test && yarn lint:typings && yarn test:typescript",
6+
"test": "yarn docs:test && yarn test:typescript",
77
"test:typescript": "tsc --noEmit && tsd",
8-
"lint": "eslint ./src",
9-
"lint:fix": "eslint ./src --fix",
10-
"lint:typings": "tslint ./typings/index.d.ts",
11-
"format": "prettier --write .",
8+
"lint": "prettier --check . && eslint src && tslint typings/index.d.ts",
9+
"format": "prettier --write . && eslint src --fix",
1210
"docs": "docgen --source ./src --custom ./docs/index.yml --output ./docs/docs.json",
1311
"docs:test": "docgen --source ./src --custom ./docs/index.yml",
1412
"prepublishOnly": "yarn lint && yarn test",

packages/discord.js/test/sendtest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3+
const fetch = require('node-fetch');
34
const fs = require('node:fs');
45
const path = require('node:path');
56
const process = require('node:process');
67
const { setTimeout: sleep } = require('node:timers/promises');
78
const util = require('node:util');
8-
const fetch = require('node-fetch');
99
const { owner, token } = require('./auth.js');
1010
const { Client, Intents, MessageAttachment, MessageEmbed } = require('../src');
1111

packages/discord.js/test/webhooktest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3+
const fetch = require('node-fetch');
34
const fs = require('node:fs');
45
const path = require('node:path');
56
const { setTimeout: sleep } = require('node:timers/promises');
67
const util = require('node:util');
7-
const fetch = require('node-fetch');
88
const { owner, token, webhookChannel, webhookToken } = require('./auth.js');
99
const { Client, Intents, MessageAttachment, MessageEmbed, WebhookClient } = require('../src');
1010

packages/rest/.eslintrc.json

-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@
77
"ignorePatterns": ["**/dist/*"],
88
"env": {
99
"jest": true
10-
},
11-
"rules": {
12-
"no-redeclare": 0,
13-
"@typescript-eslint/naming-convention": 0
1410
}
1511
}

0 commit comments

Comments
 (0)