Skip to content

Commit

Permalink
chore: update dependencies & switch to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
francislagares committed Aug 11, 2023
1 parent 40b1be3 commit eb6853e
Show file tree
Hide file tree
Showing 38 changed files with 7,909 additions and 5,022 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
40 changes: 40 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"ignorePatterns": ["node_modules", "build", "coverage"],
"env": {
"es6": true,
"node": true
},
"extends": [
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"no-var": "error",
"no-multi-spaces": "error",
"space-in-parens": "error",
"no-multiple-empty-lines": "error",
"no-constant-condition": ["error", { "checkLoops": false }],
"prefer-const": "error",
"max-lines-per-function": ["warn", 80],
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unsafe-declaration-merging": "off",
"@typescript-eslint/no-unused-vars": "off",
"prettier/prettier": [
"warn",
{
"printWidth": 80,
"singleQuote": true,
"endOfLine": "auto"
}
]
}
}
14 changes: 7 additions & 7 deletions .github/workflows/actions.yml → .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: TypeScript Compile and Test CI
name: Test

on:
push:
branches: [master]
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]
node-version: [20.x]

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Cache node_modules directory
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -34,4 +34,4 @@ jobs:
run: yarn build-ts

- name: Run Tests
run: yarn test
run: yarn test:ci
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
dist/
node_modules/
# yarn cache
.yarn/*
.yarn/cache
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions


coverage/
node_modules/
dist/
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
5 changes: 5 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

yarn commitlint --edit $1
8 changes: 8 additions & 0 deletions .husky/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
command_exists () {
command -v "$1" >/dev/null 2>&1
}

# Workaround for Windows 10, Git Bash and Yarn
if command_exists winpty && test -t 1; then
exec < /dev/tty
fi
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

yarn lint-staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn test:ci
5 changes: 5 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

exec < /dev/tty && yarn cz --hook || true
19 changes: 19 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"endOfLine": "lf",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"arrowParens": "avoid",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": true,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"useTabs": false,
"vueIndentScriptAndStyle": false
}
10 changes: 3 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${fileBasenameNoExtension}", "--config", "jest.config.js"],
"name": "Vitest Current File",
"program": "${workspaceFolder}/node_modules/.bin/vitest",
"args": ["${fileBasenameNoExtension}", "--config", "vite.config.ts"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
Expand Down
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.1.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.6.1.cjs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Data structures and algorithms implemented with TypeScript.

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/francislagares/typescript-algorithms/TypeScript%20Compile%20and%20Test%20CI?style=for-the-badge&logo=github)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/francislagares/typescript-data-structures-algorithms/tests.yaml?style=for-the-badge&logo=github)
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
// Run type-check on changes to TypeScript files
'**/*.ts?(x)': () => 'yarn type-check',
// Run ESLint on changes to JavaScript/TypeScript files
'**/*.(ts|js)?(x)': filenames => `yarn lint ${filenames.join(' ')}`,
};
60 changes: 42 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
{
"name": "typescript-algorithms",
"name": "typescript-data-structures-algorithms",
"version": "1.0.0",
"description": "Algorithms and data structures implemented in TypeScript",
"main": "dist/index.js",
"repository": "https://github.com/francislagares/typescript-algorithms.git",
"repository": "https://github.com/francislagares/typescript-data-structures-algorithms.git",
"author": "Francis Lagares",
"license": "MIT",
"scripts": {
"prepare": "husky install",
"build-ts": "tsc",
"build-dev": "tsc --watch",
"start": "nodemon dist/index.js",
"dev": "concurrently \"yarn:build-dev\" \"yarn:start\"",
"test-dev": "jest --watchAll --no-cache",
"test": "jest --verbose"
"test:ci": "vitest run",
"test:watch": "vitest watch --ui",
"test:coverage": "vitest run --coverage",
"test:report": "npx vite preview --outDir ./coverage",
"type-check": "tsc --project tsconfig.json --pretty --noEmit",
"lint": "eslint --ext js,jsx,ts,tsx --fix --ignore-path .gitignore .",
"format": "prettier --ignore-path .gitignore \"src/**/*.+(ts|js|tsx|json|md)\" --write"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
"devDependencies": {
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"@vitest/coverage-v8": "^0.34.1",
"@vitest/ui": "^0.34.1",
"commitizen": "^4.3.0",
"concurrently": "^8.2.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.46.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"nodemon": "^3.0.1",
"prettier": "^3.0.1",
"typescript": "^5.1.6",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.34.1",
"vitest-mock-extended": "^1.2.0"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/jest": "^26.0.15",
"concurrently": "^5.3.0",
"husky": "^4.3.0",
"jest": "^26.6.3",
"nodemon": "^2.0.6",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
}
"engines": {
"node": ">=20.0.0",
"npm": ">=9.6.5"
},
"packageManager": "yarn@3.6.1"
}
7 changes: 7 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["config:base"],
"semanticCommits": true,
"stabilityDays": 3,
"prCreation": "not-pending",
"labels": ["type: dependencies"]
}
8 changes: 5 additions & 3 deletions src/arrays/__tests__/arrays.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from 'vitest';

import { myArray } from '../arrayClass';

describe('Array Class Implementation', () => {
Expand All @@ -14,7 +16,7 @@ describe('Array Class Implementation', () => {
test('get value from a given index in array', () => {
const array = new myArray(
{ id: 1, name: 'Francis' },
{ id: 2, name: 'Carole' }
{ id: 2, name: 'Carole' },
);
expect(array.get(1)).toEqual({ id: 2, name: 'Carole' });
});
Expand All @@ -29,7 +31,7 @@ describe('Array Class Implementation', () => {
const array = new myArray(
['name', 'Francis'],
['name', 'Erika'],
['name', 'Peter']
['name', 'Peter'],
);
expect(array.pop()).toEqual(['name', 'Peter']);
});
Expand All @@ -39,7 +41,7 @@ describe('Array Class Implementation', () => {
{ id: 1, name: 'Francis' },
{ id: 2, name: 'Carole' },
{ id: 3, name: 'Peter' },
{ id: 4, name: 'Erika' }
{ id: 4, name: 'Erika' },
);
expect(array.delete(2)).toEqual({ id: 3, name: 'Peter' });
});
Expand Down
2 changes: 1 addition & 1 deletion src/arrays/arrayClass.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class myArray<T> {
private length: number;
private data: {};
private data: Record<string, T>;

public constructor(...args: T[]) {
this.length = args.length;
Expand Down
2 changes: 2 additions & 0 deletions src/doubly-linked-list/__tests__/DoublyLinkedList.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from 'vitest';

import { DoublyLinkedList } from '../DoublyLinkedList';

describe('Doubly Linked List', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/doubly-linked-list/__tests__/DoublyNodeList.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from 'vitest';

import { DoublyNodeList } from '../DoublyNodeList';

describe('Doubly Linked List Node', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/graph/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Graph<T> implements Graph<T> {
public addEdge(vertex: string, node: string): boolean {
// If vertex1 exists in adjacentList add vertex2 to the adjacents
// If vertex2 exists in adjacentList add vertex1 to the adjacents
let hasEdge = this.hasEdge(vertex, node);
const hasEdge = this.hasEdge(vertex, node);
if (!hasEdge) {
this.adjacentList[vertex].push(node);
this.adjacentList[node].push(vertex);
Expand All @@ -38,7 +38,7 @@ export default class Graph<T> implements Graph<T> {
}

public hasEdge(vertex: string, node: string): boolean {
let adjacents = this.adjacentList[vertex];
const adjacents = this.adjacentList[vertex];
for (let i = 0; i < adjacents.length; i++) {
if (node === adjacents[i]) return true;
}
Expand All @@ -47,8 +47,8 @@ export default class Graph<T> implements Graph<T> {

public displayConnections(): void {
const allNodes = Object.keys(this.adjacentList);
for (let node of allNodes) {
let nodeConnections = this.adjacentList[node];
for (const node of allNodes) {
const nodeConnections = this.adjacentList[node];
let connections = '';
let vertex: string;
for (vertex of nodeConnections) {
Expand Down
2 changes: 2 additions & 0 deletions src/graph/__tests__/Graph.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from 'vitest';

import Graph from '../Graph';

describe('Graphs', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/hash-table/HashTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class HashTable {
return hash;
}

public set(key: string, value: any) {
let address = this.hash(key);
public set(key: string, value: unknown) {
const address = this.hash(key);
if (!this.data[address]) {
this.data[address] = [];
}
Expand All @@ -25,7 +25,7 @@ export class HashTable {
}

public get(key: string) {
let address = this.hash(key);
const address = this.hash(key);
const currentBucket = this.data[address];
if (currentBucket) {
for (let i = 0; i < currentBucket.length; i++) {
Expand Down
Loading

0 comments on commit eb6853e

Please sign in to comment.