Skip to content

Commit

Permalink
ci: add code analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Aug 15, 2023
1 parent 34ea719 commit 00930de
Show file tree
Hide file tree
Showing 14 changed files with 670 additions and 808 deletions.
15 changes: 15 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = 1

exclude_patterns = ["tests/**"]

[[analyzers]]
name = "test-coverage"

[[analyzers]]
name = "javascript"

[analyzers.meta]
environment = [
"nodejs",
"jest"
]
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ jobs:

- name: Upload Coverage
uses: codecov/codecov-action@v3

- name: Report results to DeepSource
run: |
curl https://deepsource.io/cli | sh
./bin/deepsource report --analyzer test-coverage --key javascript --value-file ./coverage/cobertura-coverage.xml
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
2 changes: 1 addition & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"collectCoverage": true,
"collectCoverageFrom": ["src/**/*.ts"],
"coverageDirectory": "coverage",
"coverageReporters": ["text", "lcov", "clover"],
"coverageReporters": ["text", "lcov", "clover", "cobertura"],
"testMatch": ["**/?(*.)+(spec|test).[jt]s?(x)"],
"verbose": true,
"roots": ["<rootDir>/tests/"],
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,43 @@
"homepage": "https://distube.js.org/",
"dependencies": {
"@distube/ytdl-core": "^4.11.17",
"@distube/ytpl": "^1.1.1",
"@distube/ytpl": "^1.1.2",
"@distube/ytsr": "^1.1.9",
"prism-media": "npm:@distube/prism-media@latest",
"tiny-typed-emitter": "^2.1.0",
"tslib": "^2.6.1",
"undici": "^5.22.1"
"undici": "^5.23.0"
},
"devDependencies": {
"@babel/core": "^7.22.9",
"@babel/core": "^7.22.10",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-private-methods": "^7.22.5",
"@babel/preset-env": "^7.22.9",
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.22.5",
"@commitlint/cli": "^17.6.7",
"@commitlint/config-conventional": "^17.6.7",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@discordjs/voice": "^0.16.0",
"@distubejs/docgen": "distubejs/docgen",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.5",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@types/node": "^20.4.9",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"babel-jest": "^29.6.2",
"discord.js": "^14.11.0",
"eslint": "^8.45.0",
"discord.js": "^14.12.1",
"eslint": "^8.46.0",
"eslint-config-distube": "^1.6.4",
"eslint-config-prettier": "^8.9.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-deprecation": "^1.5.0",
"eslint-plugin-jsdoc": "^46.4.5",
"eslint-plugin-jsdoc": "^46.4.6",
"husky": "^8.0.3",
"jest": "^29.6.2",
"jsdoc-babel": "^0.5.0",
"nano-staged": "^0.8.0",
"npm-check-updates": "^16.10.17",
"npm-check-updates": "^16.10.18",
"pinst": "^3.0.0",
"prettier": "^3.0.0",
"tsup": "^7.1.0",
"prettier": "^3.0.1",
"tsup": "^7.2.0",
"typescript": "^5.1.6"
},
"peerDependencies": {
Expand Down
59 changes: 21 additions & 38 deletions src/DisTube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
this.filters = { ...defaultFilters, ...this.options.customFilters };
// Default plugin
if (this.options.directLink) this.options.plugins.push(new DirectLinkPlugin());
this.options.plugins.map(p => p.init(this));
this.options.plugins.forEach(p => p.init(this));
/**
* Extractor Plugins
* @type {ExtractorPlugin[]}
Expand Down Expand Up @@ -255,13 +255,13 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
const promises = filteredSongs.map((song: string | Song | SearchResult) =>
this.handler.resolve(song, { member, metadata }).catch(() => undefined),
);
resolvedSongs = (await Promise.all(promises)).filter((s: any): s is Song => !!s);
resolvedSongs = (await Promise.all(promises)).filter((s: any): s is Song => Boolean(s));
} else {
const resolved = [];
for (const song of filteredSongs) {
resolved.push(await this.handler.resolve(song, { member, metadata }).catch(() => undefined));
}
resolvedSongs = resolved.filter((s: any): s is Song => !!s);
resolvedSongs = resolved.filter((s: any): s is Song => Boolean(s));
}
return new Playlist(resolvedSongs, { member, properties, metadata });
}
Expand Down Expand Up @@ -346,16 +346,20 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
return this.queues.get(guild);
}

#getQueue(guild: GuildIdResolvable): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q;
}

/**
* Pause the guild stream
* @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
* @returns {Queue} The guild queue
* @throws {Error}
*/
pause(guild: GuildIdResolvable): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.pause();
return this.#getQueue(guild).pause();
}

/**
Expand All @@ -365,9 +369,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* @throws {Error}
*/
resume(guild: GuildIdResolvable): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.resume();
return this.#getQueue(guild).resume();
}

/**
Expand All @@ -387,9 +389,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
stop(guild: GuildIdResolvable): Promise<void> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.stop();
return this.#getQueue(guild).stop();
}

/**
Expand All @@ -408,9 +408,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
setVolume(guild: GuildIdResolvable, percent: number): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.setVolume(percent);
return this.#getQueue(guild).setVolume(percent);
}

/**
Expand All @@ -430,9 +428,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
skip(guild: GuildIdResolvable): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.skip();
return this.#getQueue(guild).skip();
}

/**
Expand All @@ -450,9 +446,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
previous(guild: GuildIdResolvable): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.previous();
return this.#getQueue(guild).previous();
}

/**
Expand All @@ -469,9 +463,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
shuffle(guild: GuildIdResolvable): Promise<Queue> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.shuffle();
return this.#getQueue(guild).shuffle();
}

/**
Expand All @@ -493,9 +485,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
jump(guild: GuildIdResolvable, num: number): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.jump(num);
return this.#getQueue(guild).jump(num);
}

/**
Expand Down Expand Up @@ -532,9 +522,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* message.channel.send("Set repeat mode to `" + mode + "`");
*/
setRepeatMode(guild: GuildIdResolvable, mode?: number): number {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.setRepeatMode(mode);
return this.#getQueue(guild).setRepeatMode(mode);
}

/**
Expand All @@ -554,8 +542,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
toggleAutoplay(guild: GuildIdResolvable): boolean {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
const q = this.#getQueue(guild);
q.autoplay = !q.autoplay;
return q.autoplay;
}
Expand All @@ -566,9 +553,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* @returns {Promise<Song>} The guild queue
*/
addRelatedSong(guild: GuildIdResolvable): Promise<Song> {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.addRelatedSong();
return this.#getQueue(guild).addRelatedSong();
}

/**
Expand All @@ -586,9 +571,7 @@ export class DisTube extends TypedEmitter<TypedDisTubeEvents> {
* });
*/
seek(guild: GuildIdResolvable, time: number): Queue {
const q = this.getQueue(guild);
if (!q) throw new DisTubeError("NO_QUEUE");
return q.seek(time);
return this.#getQueue(guild).seek(time);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/DisTubeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class DisTubeHandler extends DisTubeBase {
query?: string,
): Promise<R | null> {
if (!isMessageInstance(message)) throw new DisTubeError("INVALID_TYPE", "Discord.Message", message, "message");
if (!Array.isArray(results) || results.length == 0) {
if (!Array.isArray(results) || results.length === 0) {
throw new DisTubeError("INVALID_TYPE", "Array<SearchResult|Song|Playlist>", results, "results");
}
if (this.options.searchSongs > 1) {
Expand Down
Loading

0 comments on commit 00930de

Please sign in to comment.