Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b99bb7e

Browse files
authoredNov 10, 2023
style: add eslint (#1)
1 parent 1c9a95c commit b99bb7e

17 files changed

+205
-184
lines changed
 

‎.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.eslintrc.cjs

‎.eslintrc.cjs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
extends: ['airbnb-base', 'airbnb-typescript/base'],
3+
parserOptions: {
4+
project: './tsconfig.eslint.json',
5+
},
6+
rules: {
7+
'import/prefer-default-export': 0,
8+
},
9+
};

‎.prettierrc.js ‎.prettierrc.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default {
1+
module.exports = {
22
trailingComma: 'all',
33
singleQuote: true,
44
arrowParens: 'always',
5-
}
5+
};

‎bun.lockb

61.2 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default {
1+
module.exports = {
22
extends: ['@commitlint/config-conventional'],
33
};

‎package.json

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"start": "bun run src/index.ts",
77
"commit": "cz",
8+
"lint": "eslint . --fix --ext .ts",
89
"test": "bun test",
910
"test:watch": "bun test --watch",
1011
"prepare": "husky install"
@@ -19,5 +20,10 @@
1920
},
2021
"peerDependencies": {
2122
"typescript": "^5.0.0"
23+
},
24+
"dependencies": {
25+
"@typescript-eslint/eslint-plugin": "^6.0.0",
26+
"@typescript-eslint/parser": "^6.0.0",
27+
"eslint-config-airbnb-typescript": "^17.1.0"
2228
}
2329
}

‎src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log("Hello via Bun!");
1+
console.log('Hello via Bun!');
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./linked-list-node";
1+
export * from './linked-list-node';
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { describe, it, expect } from "bun:test";
2-
import { LinkedListNode } from "./linked-list-node";
1+
import { describe, it, expect } from 'bun:test';
2+
import { LinkedListNode } from './linked-list-node';
33

4-
describe("LinkedListNode", () => {
5-
it("should create list node with value", () => {
4+
describe('LinkedListNode', () => {
5+
it('should create list node with value', () => {
66
const node = new LinkedListNode(1);
77

88
expect(node.data).toEqual(1);
99
expect(node.next).toBeNull();
1010
});
1111

12-
it("should create list node with object as a value", () => {
12+
it('should create list node with object as a value', () => {
1313
const nodeValue = {
1414
value: 1,
15-
key: "test",
15+
key: 'test',
1616
};
1717
const node = new LinkedListNode(nodeValue);
1818

1919
expect(node.data.value).toEqual(1);
20-
expect(node.data.key).toEqual("test");
20+
expect(node.data.key).toEqual('test');
2121
expect(node.next).toBeNull();
2222
});
2323

24-
it("should link nodes together", () => {
24+
it('should link nodes together', () => {
2525
const node2 = new LinkedListNode(1);
2626
const node1 = new LinkedListNode(2, node2);
2727

@@ -31,11 +31,11 @@ describe("LinkedListNode", () => {
3131
expect(node1.next.data).toEqual(1);
3232
});
3333

34-
it("should convert node to string", () => {
34+
it('should convert node to string', () => {
3535
const node = new LinkedListNode(1);
36-
expect(node.toString()).toEqual("1");
36+
expect(node.toString()).toEqual('1');
3737

38-
node.data = "new value";
39-
expect(node.toString()).toEqual("new value");
38+
node.data = 'new value';
39+
expect(node.toString()).toEqual('new value');
4040
});
4141
});

‎src/linked-list/linked-list-node/linked-list-node.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type Callback<T> = (data: T) => string;
22

33
export class LinkedListNode<T = any> {
44
data: T;
5+
56
next: LinkedListNode<T> | null;
67

78
constructor(data: any, next: LinkedListNode<T> | null = null) {

‎src/linked-list/linked-list/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
const LinkedList = require('./linked-list');
2-
3-
1+
export * from './linked-list';

‎src/linked-list/linked-list/linked-list.test.js

+138-138
Large diffs are not rendered by default.

‎src/linked-list/linked-list/linked-list.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Comparator } from "../../utils/comparator";
2-
import type { CompareFunction } from "../../utils/comparator";
3-
import { LinkedListNode } from "../linked-list-node";
4-
import type { Callback } from "../linked-list-node";
1+
import { Comparator } from '../../utils/comparator';
2+
import type { CompareFunction } from '../../utils/comparator';
3+
import { LinkedListNode } from '../linked-list-node';
4+
import type { Callback } from '../linked-list-node';
55

66
interface FindOptions<T = any> {
77
data?: T;
@@ -10,8 +10,11 @@ interface FindOptions<T = any> {
1010

1111
export class LinkedList<T = any> {
1212
head: LinkedListNode<T> | null;
13+
1314
tail: LinkedListNode<T> | null;
15+
1416
length: number;
17+
1518
#compare;
1619

1720
constructor(compareFunction: CompareFunction<T>) {
@@ -34,18 +37,17 @@ export class LinkedList<T = any> {
3437
this.tail = newNode;
3538

3639
return this;
37-
} else {
38-
this.tail!.next = newNode;
39-
this.tail = newNode;
4040
}
41+
this.tail!.next = newNode;
42+
this.tail = newNode;
4143

4244
return this;
4345
}
4446

4547
toArray() {
4648
if (!this.head) return [];
4749

48-
let nodes = [] as LinkedListNode<T>[];
50+
const nodes = [] as LinkedListNode<T>[];
4951
let currentNode = this.head as LinkedListNode<T> | null;
5052

5153
while (currentNode) {
@@ -106,7 +108,7 @@ export class LinkedList<T = any> {
106108
let prevNode = null;
107109

108110
while (currentNode) {
109-
let nextNode = currentNode.next;
111+
const nextNode = currentNode.next;
110112
currentNode.next = prevNode;
111113

112114
prevNode = currentNode;
@@ -204,7 +206,7 @@ export class LinkedList<T = any> {
204206
deleteHead() {
205207
if (!this.head) return null;
206208

207-
let deletedHead = this.head;
209+
const deletedHead = this.head;
208210

209211
if (deletedHead.next) {
210212
this.head = deletedHead.next;
+14-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { describe, expect, it } from "bun:test";
2-
import { Comparator } from "./comparator";
1+
import { describe, expect, it } from 'bun:test';
2+
import { Comparator } from './comparator';
33

4-
describe("Comparator", () => {
5-
it("should compare with default comparator function", () => {
4+
describe('Comparator', () => {
5+
it('should compare with default comparator function', () => {
66
// Arrange
77
const comparator = new Comparator();
88

99
// Act and Assert
1010
expect(comparator.equal(0, 0)).toBeTruthy();
1111
expect(comparator.equal(1, 0)).toBeFalsy();
12-
expect(comparator.equal("a", "a")).toBeTruthy();
12+
expect(comparator.equal('a', 'a')).toBeTruthy();
1313
expect(comparator.lessThan(1, 2)).toBeTruthy();
1414
expect(comparator.lessThan(-1, 2)).toBeTruthy();
15-
expect(comparator.lessThan("a", "b")).toBeTruthy();
16-
expect(comparator.lessThan("a", "ab")).toBeTruthy();
15+
expect(comparator.lessThan('a', 'b')).toBeTruthy();
16+
expect(comparator.lessThan('a', 'ab')).toBeTruthy();
1717
expect(comparator.lessThan(10, 2)).toBeFalsy();
1818
expect(comparator.lessThanOrEqual(1, 1)).toBeTruthy();
1919
expect(comparator.lessThanOrEqual(0, 0)).toBeTruthy();
@@ -24,7 +24,7 @@ describe("Comparator", () => {
2424
expect(comparator.greaterThanOrEqual(0, 10)).toBeFalsy();
2525
});
2626

27-
it("should compare with custom comparator function", () => {
27+
it('should compare with custom comparator function', () => {
2828
// Arrange
2929
const comparator = new Comparator((a: string, b: string) => {
3030
if (a.length === b.length) return 0;
@@ -33,11 +33,11 @@ describe("Comparator", () => {
3333
});
3434

3535
// Act and Assert
36-
expect(comparator.equal("a", "b")).toBeTruthy();
37-
expect(comparator.equal("a", "")).toBeFalsy();
38-
expect(comparator.lessThan("b", "aa")).toBeTruthy();
39-
expect(comparator.greaterThanOrEqual("a", "aa")).toBeFalsy();
40-
expect(comparator.greaterThanOrEqual("aa", "a")).toBeTruthy();
41-
expect(comparator.greaterThanOrEqual("a", "a")).toBeTruthy();
36+
expect(comparator.equal('a', 'b')).toBeTruthy();
37+
expect(comparator.equal('a', '')).toBeFalsy();
38+
expect(comparator.lessThan('b', 'aa')).toBeTruthy();
39+
expect(comparator.greaterThanOrEqual('a', 'aa')).toBeFalsy();
40+
expect(comparator.greaterThanOrEqual('aa', 'a')).toBeTruthy();
41+
expect(comparator.greaterThanOrEqual('a', 'a')).toBeTruthy();
4242
});
4343
});

‎src/utils/comparator/comparator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Comparator<T = any> {
3434
}
3535

3636
reverse(): void {
37-
let originalCompare = this.compare;
37+
const originalCompare = this.compare;
3838
this.compare = (a: T, b: T) => originalCompare(a, b);
3939
}
4040
}

‎src/utils/comparator/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./comparator";
1+
export * from './comparator';

‎tsconfig.eslint.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*.ts"],
4+
}

0 commit comments

Comments
 (0)
Please sign in to comment.