Skip to content

Commit b916ece

Browse files
committed
feat: add explicit return types to functions in mergeSortCounters and BinaryTree classes; update ESLint configuration for function return type enforcement
1 parent 3458fa1 commit b916ece

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

algorithms/sorting/merge-sort-counters/mergeSortCounters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let countOuter = 0;
77
let countInner = 0;
88
let countSwap = 0;
99

10-
function resetCounters() {
10+
function resetCounters(): void {
1111
countOuter = 0;
1212
countInner = 0;
1313
countSwap = 0;

data-structures/binary-tree/binaryTree.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class BinaryTree<T> {
1010
* Inserts a new value into the binary search tree.
1111
* @param {T} value The value to insert.
1212
*/
13-
insert(value: T) {
13+
insert(value: T): void {
1414
const newNode = new BinaryTreeNode(value);
1515
if (this.root === null) {
1616
this.root = newNode;
@@ -19,7 +19,10 @@ export class BinaryTree<T> {
1919
}
2020
}
2121

22-
private insertNode(node: BinaryTreeNode<T>, newNode: BinaryTreeNode<T>) {
22+
private insertNode(
23+
node: BinaryTreeNode<T>,
24+
newNode: BinaryTreeNode<T>
25+
): void {
2326
if (newNode.value < node.value) {
2427
if (node.left === null) {
2528
node.left = newNode;
@@ -65,8 +68,8 @@ export class BinaryTree<T> {
6568
* Traverses the binary search tree in order (left, root, right).
6669
* @param {function} visit Function to call on each value.
6770
*/
68-
inOrderTraverse(visit: (value: T) => void) {
69-
function traverse(node: BinaryTreeNode<T> | null) {
71+
inOrderTraverse(visit: (value: T) => void): void {
72+
function traverse(node: BinaryTreeNode<T> | null): void {
7073
if (node === null) return;
7174
traverse(node.left);
7275
visit(node.value);
@@ -79,7 +82,7 @@ export class BinaryTree<T> {
7982
* Removes a value from the binary search tree.
8083
* @param {T} value The value to remove.
8184
*/
82-
remove(value: T) {
85+
remove(value: T): void {
8386
this.root = this.removeNode(this.root, value);
8487
}
8588

eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module.exports = [
2020
"no-irregular-whitespace": ["error", { skipTemplates: true }],
2121
"@typescript-eslint/no-unused-vars": "error",
2222
"@typescript-eslint/no-useless-constructor": "error",
23+
"@typescript-eslint/explicit-function-return-type": ["warn", {
24+
allowExpressions: true,
25+
allowTypedFunctionExpressions: true,
26+
}],
2327
"@typescript-eslint/no-floating-promises": "error",
2428
"@typescript-eslint/await-thenable": "error",
2529
"eqeqeq": ["error", "always", { null: "ignore" }],

0 commit comments

Comments
 (0)