[project] ESLint applied

This commit is contained in:
Revone 2023-09-20 11:39:24 +08:00
parent a780e60844
commit 95b44f439b
19 changed files with 2775 additions and 92 deletions

65
.eslintrc.json Normal file
View file

@ -0,0 +1,65 @@
{
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"react/display-name": "off",
"@next/next/no-img-element": "off",
"react/no-unescaped-entities": "off",
"import/no-anonymous-default-export": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
// add new line above comment
"lines-around-comment": [
"error",
{
"beforeLineComment": false,
"beforeBlockComment": true,
"allowBlockStart": true,
"allowClassStart": true,
"allowObjectStart": true,
"allowArrayStart": true
}
],
// add new line above return
"newline-before-return": "off",
// add new line below import
"import/newline-after-import": [
"error",
{
"count": 1
}
],
"@typescript-eslint/ban-types": [
"error",
{
"extendDefaults": true,
"types": {
"{}": false
}
}
]
},
"plugins": [
"import"
],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx"
]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": [
"./tsconfig.json"
]
}
}
}
}

View file

@ -1,9 +1,6 @@
/.idea
/src
/tests
/notes
/docs
/backup
.editorconfig

View file

@ -53,22 +53,21 @@ const {Heap, MinHeap, SinglyLinkedList, Stack, AVLTreeNode, BST, Trie, DirectedG
bst.add(11);
bst.add(3);
bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
bst.size === 16; // true
bst.has(6); // true
const node6 = bst.get(6);
bst.getHeight(6) === 2; // true
bst.getHeight() === 5; // true
bst.getDepth(6) === 3; // true
const leftMost = bst.getLeftMost();
leftMost?.id === 1; // true
expect(leftMost?.id).toBe(1);
bst.size === 16; // true
bst.has(6); // true
const node6 = bst.get(6); // BSTNode
bst.getHeight(6) === 2; // true
bst.getHeight() === 5; // true
bst.getDepth(6) === 3; // true
bst.getLeftMost()?.id === 1; // true
bst.remove(6);
bst.get(6); // null
bst.isAVLBalanced(); // true or false
const bfsIDs = bst.BFS();
bfsIDs[0] === 11; // true
expect(bfsIDs[0]).toBe(11);
bst.get(6); // null
bst.isAVLBalanced(); // true
bst.BFS()[0] === 11; // true
const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
objBST.add(11, {id: 11, keyA: 11});
objBST.add(3, {id: 3, keyA: 3});
@ -80,14 +79,6 @@ const {Heap, MinHeap, SinglyLinkedList, Stack, AVLTreeNode, BST, Trie, DirectedG
{id: 10, keyA: 10}, {id: 5, keyA: 5}]);
objBST.remove(11);
const avlTree = new AVLTree();
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
avlTree.isAVLBalanced(); // true
avlTree.remove(10);
avlTree.isAVLBalanced(); // true
```
#### JS
```javascript
@ -134,6 +125,30 @@ const {Heap, MinHeap, SinglyLinkedList, Stack, AVLTreeNode, BST, Trie, DirectedG
```
### AVLTree snippet
#### TS
```typescript
import {AVLTree} from 'data-structure-typed';
const avlTree = new AVLTree();
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
avlTree.isAVLBalanced(); // true
avlTree.remove(10);
avlTree.isAVLBalanced(); // true
```
#### JS
```javascript
const {AVLTree} = require('data-structure-typed');
const avlTree = new AVLTree();
avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
avlTree.isAVLBalanced(); // true
avlTree.remove(10);
avlTree.isAVLBalanced(); // true
```
### Directed Graph simple snippet
#### TS or JS
```typescript

2622
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,8 @@
"build": "rm -rf dist && npx tsc && npm run build:browser",
"build:browser": "webpack",
"build:docs": "typedoc --out docs ./src",
"lint": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
"test": "jest",
"update:test-deps": "npm i avl-tree-typed binary-tree-typed bst-typed deque-typed directed-graph-typed doubly-linked-list-typed graph-typed heap-typed linked-list-typed max-heap-typed max-priority-queue-typed min-heap-typed min-priority-queue-typed priority-queue-typed singly-linked-list-typed stack-typed tree-multiset-typed trie-typed undirected-graph-typed queue-typed --save-dev",
"deps:check": "dependency-cruiser src",
@ -26,7 +28,6 @@
"data-structure",
"data structures",
"data-structures",
"binary",
"depth",
"breadth",
@ -38,30 +39,24 @@
"prefix",
"tree",
"multiset",
"directed",
"undirected",
"graph",
"min",
"max",
"heap",
"priority",
"queue",
"singly",
"doubly",
"linked",
"list",
"js",
"ts",
"javascript",
"typscript",
"sort",
"algorithm",
"binary search tree",
"binary-search-tree",
"binary tree",
@ -79,7 +74,6 @@
"trie",
"prefix tree",
"prefix-tree",
"dfs",
"DFS",
"depth first Search",
@ -91,17 +85,14 @@
"DFS Iterative",
"recursive",
"iterative",
"directed graph",
"directed-graph",
"undirected graph",
"undirected-graph",
"min heap",
"min-heap",
"max heap",
"max-heap",
"priority queue",
"priority-queue",
"max priority queue",
@ -110,21 +101,17 @@
"min-priority-queue",
"array queue",
"array-queue",
"stack",
"hash",
"deque",
"object deque",
"array deque",
"linked list",
"linked-list",
"singly linked list",
"singly-linked-list",
"doubly linked list",
"doubly-linked-list",
"morris",
"Morris",
"bellman ford",
@ -138,7 +125,6 @@
"tarjan",
"Tarjan",
"Tarjan's",
"DataStructure",
"DataStructures"
],
@ -151,6 +137,8 @@
"devDependencies": {
"@types/jest": "^29.5.3",
"@types/node": "^20.4.9",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.11.0",
"avl-tree-typed": "^1.3.3",
"binary-tree-typed": "^1.3.3",
"bst-typed": "^1.3.3",
@ -158,6 +146,11 @@
"deque-typed": "^1.3.3",
"directed-graph-typed": "^1.3.3",
"doubly-linked-list-typed": "^1.3.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.4",
"graph-typed": "^1.3.3",
"heap-typed": "^1.3.3",
"jest": "^29.6.2",
@ -166,6 +159,7 @@
"max-priority-queue-typed": "^1.3.3",
"min-heap-typed": "^1.3.3",
"min-priority-queue-typed": "^1.3.3",
"prettier": "^3.0.3",
"priority-queue-typed": "^1.3.3",
"queue-typed": "^1.3.3",
"singly-linked-list-typed": "^1.3.3",

View file

@ -69,29 +69,29 @@ export class RBTree<N extends RBTreeNode<N['val'], N> = RBTreeNode> extends BST<
// return this._root;
// }
insert(id: number, val?: N | null) {
}
private leftRotate(node: N) {
}
private rightRotate(node: N) {
}
private insertFixup(node: N) {
}
private deleteFixup(node: N) {
}
private transplant(u: N, v: N) {
}
// insert(id: number, val?: N | null) {
//
// }
//
// private leftRotate(node: N) {
//
// }
//
// private rightRotate(node: N) {
//
// }
//
// private insertFixup(node: N) {
//
// }
//
// private deleteFixup(node: N) {
//
// }
//
// private transplant(u: N, v: N) {
//
// }
// override remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<N>[] {
//

View file

@ -158,7 +158,7 @@ export class SegmentTree {
const dfs = (cur: SegmentTreeNode, index: number, sum: number, val?: SegmentTreeNodeVal) => {
if (cur.start === cur.end && cur.start === index) {
cur.sum = sum;
// cur.val = val;
if (val !== undefined) cur.val = val;
return;
}
const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
@ -176,7 +176,7 @@ export class SegmentTree {
}
};
dfs(root, index, sum);
dfs(root, index, sum, val);
}
/**

View file

@ -11,7 +11,7 @@ export class CoordinateMap<V> extends Map<any, V> {
if (joint !== undefined) this._joint = joint;
}
protected _joint: string = '_';
protected _joint = '_';
get joint(): string {
return this._joint;

View file

@ -11,7 +11,7 @@ export class CoordinateSet extends Set<any> {
if (joint !== undefined) this._joint = joint;
}
protected _joint: string = '_';
protected _joint = '_';
get joint(): string {
return this._joint;

View file

@ -11,6 +11,7 @@ import type {PriorityQueueOptions, SpecifyOptional} from '../../types';
export class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>)
constructor(options: PriorityQueueOptions<T>)
/**
* The constructor initializes a priority queue with an optional comparator function.
* @param [options] - The `options` parameter is an optional object that can contain various properties to configure
@ -28,6 +29,7 @@ export class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
static override heapify<T extends number>(options?: Omit<PriorityQueueOptions<T>, 'comparator'>): MaxPriorityQueue<T>
static override heapify<T>(options: PriorityQueueOptions<T>): MaxPriorityQueue<T>
/**
* The function `heapify` creates a max priority queue from the given options and returns it.
* @param options - The `options` parameter is an object that contains configuration options for creating a priority

View file

@ -11,6 +11,7 @@ import type {PriorityQueueOptions, SpecifyOptional} from '../../types';
export class MinPriorityQueue<T = number> extends PriorityQueue<T> {
constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>)
constructor(options: PriorityQueueOptions<T>)
/**
* The constructor initializes a priority queue with an optional comparator function.
* @param [options] - The `options` parameter is an optional object that can contain various configuration options for
@ -28,6 +29,7 @@ export class MinPriorityQueue<T = number> extends PriorityQueue<T> {
static override heapify<T extends number>(options?: Omit<PriorityQueueOptions<T>, 'comparator'>): MinPriorityQueue<T>
static override heapify<T>(options: PriorityQueueOptions<T>): MinPriorityQueue<T>
/**
* The function `heapify` creates a new MinPriorityQueue instance and sets the comparator function based on the options
* provided, and then fixes the heap structure of the queue.

View file

@ -37,7 +37,7 @@ export class ObjectDeque<T = number> {
this._capacity = value;
}
private _first: number = -1;
private _first = -1;
get first(): number {
return this._first;
@ -47,7 +47,7 @@ export class ObjectDeque<T = number> {
this._first = value;
}
private _last: number = -1;
private _last = -1;
get last(): number {
return this._last;
@ -57,7 +57,7 @@ export class ObjectDeque<T = number> {
this._last = value;
}
private _size: number = 0;
private _size = 0;
get size(): number {
return this._size;

View file

@ -2,9 +2,7 @@ import {AVLTreeNode} from '../data-structures';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeDeletedResult, BinaryTreeNodeId} from '../types';
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
}
export type IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {

View file

@ -1,8 +1,6 @@
import {BinaryTreeNode} from '../data-structures';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from './abstract-binary-tree';
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
}
export type IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> = IAbstractBinaryTreeNode<T, NEIGHBOR>
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
}
export type IBinaryTree<N extends BinaryTreeNode<N['val'], N>> = IAbstractBinaryTree<N>

View file

@ -2,8 +2,7 @@ import {BSTNode} from '../data-structures';
import {IBinaryTree, IBinaryTreeNode} from './binary-tree';
import {BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName} from '../types';
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
}
export type IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> = IBinaryTreeNode<T, NEIGHBOR>
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N

View file

@ -2,8 +2,7 @@ import {RBTreeNode} from '../data-structures';
import {IBST, IBSTNode} from './bst';
import {BinaryTreeNodeId} from '../types';
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
}
export type IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {

View file

@ -2,10 +2,6 @@ import {TreeMultisetNode} from '../data-structures';
import {IBSTNode} from './bst';
import {IAVLTree} from './avl-tree';
export interface ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
export type ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> = IBSTNode<T, NEIGHBOR>
}
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {
}
export type ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> = IAVLTree<N>

View file

@ -1,5 +1,5 @@
export type ToThunkFn = () => ReturnType<TrlFn>;
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: Symbol };
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
export type TrlFn = (...args: any[]) => any;
export type TrlAsyncFn = (...args: any[]) => any;

View file

@ -22,4 +22,4 @@ export type RestrictValById =
| ObjectWithNonNumberId
| ObjectWithNumberId;
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | Function | never;
export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | ((...args: []) => any) | never;