From 2f35776696777ff5d6e19c5c9e76e4b70804c828 Mon Sep 17 00:00:00 2001 From: wieerwill Date: Wed, 6 Dec 2023 21:05:52 +0100 Subject: [PATCH] fix lint rules and small readme improve --- .eslintrc.js | 4 ++++ .github/workflows/lint.yml | 2 +- Analytics.md | 43 ++++++++++++++++++++------------------ Day01/js/solution.js | 4 +--- Day01/ts/solution.ts | 2 -- Day04/ts/solution.ts | 18 +++++++++++----- Day05/ts/solution.ts | 2 +- README.md | 5 +++++ measure_performance.sh | 43 ++++++++++++-------------------------- package-lock.json | 8 +++++++ package.json | 3 +++ tsconfig.json | 2 +- 12 files changed, 73 insertions(+), 63 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5f42ca5..66a9b29 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,8 @@ module.exports = { + env: { + node: true, // Indicates that the code runs in a Node.js environment + es2021: true + }, root: true, parser: "@typescript-eslint/parser", parserOptions: { diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index dc30b08..3f72157 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -33,7 +33,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: '14' + node-version: '16' # Lint JavaScript files - name: Lint JavaScript diff --git a/Analytics.md b/Analytics.md index f920beb..f591e0b 100644 --- a/Analytics.md +++ b/Analytics.md @@ -1,26 +1,29 @@ # Performance Analytics + ## Day01 -| Language | Status | Real Time | User Time | Sys Time | -| --- | --- | --- | --- | --- | -| Python | 0 | 0m0,071s | 0m0,060s | 0m0,008s | -| Rust | 0 | 0m0,078s | 0m0,052s | 0m0,026s | -| JavaScript | 0 | 0m0,089s | 0m0,085s | 0m0,012s | -| TypeScript | 0 | 0m1,001s | 0m2,188s | 0m0,158s | +| Language | Status | Real Time | User Time | Sys Time | +| ---------- | ------- | --------- | --------- | -------- | +| Python | Success | 0m0,090s | 0m0,073s | 0m0,017s | +| Rust | Success | 0m0,057s | 0m0,049s | 0m0,008s | +| JavaScript | Success | 0m0,080s | 0m0,068s | 0m0,020s | +| TypeScript | Failed | - | - | - | + ## Day02 -| Language | Status | Real Time | User Time | Sys Time | -| --- | --- | --- | --- | --- | -| Python | 0 | 0m0,032s | 0m0,016s | 0m0,016s | -| Rust | 0 | 0m0,063s | 0m0,044s | 0m0,020s | -| JavaScript | 0 | 0m0,044s | 0m0,032s | 0m0,012s | -| TypeScript | 0 | 0m1,013s | 0m2,059s | 0m0,160s | +| Language | Status | Real Time | User Time | Sys Time | +| ---------- | ------- | --------- | --------- | -------- | +| Python | Success | 0m0,047s | 0m0,039s | 0m0,008s | +| Rust | Success | 0m0,059s | 0m0,032s | 0m0,028s | +| JavaScript | Success | 0m0,046s | 0m0,031s | 0m0,015s | +| TypeScript | Failed | - | - | - | + ## Day03 -| Language | Status | Real Time | User Time | Sys Time | -| --- | --- | --- | --- | --- | -| Python | 0 | 0m0,054s | 0m0,043s | 0m0,011s | -| Rust | 0 | 0m0,059s | 0m0,032s | 0m0,024s | -| JavaScript | 0 | 0m0,067s | 0m0,036s | 0m0,032s | -| TypeScript | 0 | 0m1,014s | 0m2,128s | 0m0,155s | +| Language | Status | Real Time | User Time | Sys Time | +| ---------- | ------- | --------- | --------- | -------- | +| Python | Success | 0m0,042s | 0m0,033s | 0m0,008s | +| Rust | Success | 0m0,066s | 0m0,054s | 0m0,012s | +| JavaScript | Success | 0m0,076s | 0m0,061s | 0m0,016s | +| TypeScript | Failed | - | - | - | + ## Day04 | Language | Status | Real Time | User Time | Sys Time | -| --- | --- | --- | --- | --- | -| Python | 0 | 0m16,137s | 0m16,020s | 0m0,117s | +| -------- | ------ | --------- | --------- | -------- | diff --git a/Day01/js/solution.js b/Day01/js/solution.js index 2731ed5..dd8b4bd 100644 --- a/Day01/js/solution.js +++ b/Day01/js/solution.js @@ -15,12 +15,10 @@ function extractDigits(line) { let digitsFound = []; let i = 0; while (i < line.length) { - let matched = false; for (const [word, digit] of Object.entries(digitMap)) { if (line.startsWith(word, i)) { digitsFound.push(digit); - i += word.length - 1; // Advance the index - matched = true; + i += word.length - 1; break; } } diff --git a/Day01/ts/solution.ts b/Day01/ts/solution.ts index c2b6929..41bacb9 100644 --- a/Day01/ts/solution.ts +++ b/Day01/ts/solution.ts @@ -14,12 +14,10 @@ function extractDigits(line: string): number[] { const digitsFound: number[] = []; let i = 0; while (i < line.length) { - let matched = false; for (const [word, digit] of Object.entries(digitMap)) { if (line.startsWith(word, i)) { digitsFound.push(digit); i += word.length - 1; - matched = true; break; } } diff --git a/Day04/ts/solution.ts b/Day04/ts/solution.ts index 0d8b54b..2dca5d5 100644 --- a/Day04/ts/solution.ts +++ b/Day04/ts/solution.ts @@ -47,9 +47,13 @@ function processFile(filePath: string): number | null { const lines = data.trim().split('\n'); const cards = lines.map(parseCardData); return processCards(cards); - } catch (error: any) { - console.error(`Error processing file ${filePath}: ${error.message}`); - return null; + } catch (error) { + if (error instanceof Error) { + console.error(`Error processing file ${filePath}: ${error.message}`); + return null; + } else { + console.error(`An unknown error occurred`); + } } } @@ -67,8 +71,12 @@ function main() { test(); const totalCards = processFile('../input.txt'); console.log(`Total cards from input.txt: ${totalCards}`); - } catch (error: any) { - console.error(`An error occurred: ${error.message}`); + } catch (error) { + if (error instanceof Error) { + console.error(`An error occurred: ${error.message}`); + } else { + console.error(`An unknown error occurred`); + } } } diff --git a/Day05/ts/solution.ts b/Day05/ts/solution.ts index ef6ae76..0f6e382 100644 --- a/Day05/ts/solution.ts +++ b/Day05/ts/solution.ts @@ -29,7 +29,7 @@ function processCategories(seedsNumbers: number[][], categories: number[][][]): console.log('Processing categories'); categories.forEach((category, index) => { console.log(`Processing category ${index + 1}`); - let sources: number[][] = []; + const sources: number[][] = []; while (seedsNumbers.length) { const seedPair = seedsNumbers.pop(); if (!seedPair) { diff --git a/README.md b/README.md index 92450bd..b1797cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # 🎄 Advent of Code 2023 🎄 +![Build Status](https://github.com/wieerwill/advent_of_code_2023/actions/workflows/lint.yml/badge.svg) +![Coverage](https://codecov.io/gh/wieerwill/advent_of_code_2023/branch/main/graph/badge.svg) +![Dependencies Status](https://david-dm.org/wieerwill/advent_of_code_2023.svg) +![License](https://img.shields.io/github/license/wieerwill/advent_of_code_2023.svg) + Welcome to my repository where I share my solutions for the [Advent of Code 2023](https://adventofcode.com/2023). Advent of Code is an annual online event where participants solve a series of programming puzzles released daily from December 1st until December 25th. Each puzzle is a fun and unique challenge designed to test problem-solving skills. ## Structure diff --git a/measure_performance.sh b/measure_performance.sh index 49f214a..eb01639 100755 --- a/measure_performance.sh +++ b/measure_performance.sh @@ -17,44 +17,26 @@ measure_execution_time() { echo "Running $language script for $day: $runner $script_dir$script_name" - local real_time="" - local user_time="" - local sys_time="" - local EXEC_STATUS="" - cd "$script_dir" - if [ "$language" == "Rust" ]; then - if [ -d "$script_dir" ]; then - exec 3>&1 4>&2 - TIME_RESULT=$( { time $runner 1>&3 2>&4; } 2>&1 ) - EXEC_STATUS=$? - exec 3>&- 4>&- + if [ -f "$script_name" ] || [ "$language" == "Rust" ]; then + exec 3>&1 4>&2 + TIME_RESULT=$( { time $runner $script_name 1>&3 2>&4; } 2>&1 ) + EXEC_STATUS=$? + exec 3>&- 4>&- + if [ $EXEC_STATUS -eq 0 ]; then real_time=$(echo "$TIME_RESULT" | grep real | awk '{print $2}') user_time=$(echo "$TIME_RESULT" | grep user | awk '{print $2}') sys_time=$(echo "$TIME_RESULT" | grep sys | awk '{print $2}') - echo "| $language | $EXEC_STATUS | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE" + echo "| $language | Success | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE" else - echo "| $language | rust not executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE" - echo "Warning: $language script for $day not found or not executable" + echo "| $language | Failed | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE" + echo "Warning: $language script for $day failed with status $EXEC_STATUS" fi else - if [ -f "$script_name" ]; then - exec 3>&1 4>&2 - TIME_RESULT=$( { time $runner $script_name 1>&3 2>&4; } 2>&1 ) - EXEC_STATUS=$? - exec 3>&- 4>&- - - real_time=$(echo "$TIME_RESULT" | grep real | awk '{print $2}') - user_time=$(echo "$TIME_RESULT" | grep user | awk '{print $2}') - sys_time=$(echo "$TIME_RESULT" | grep sys | awk '{print $2}') - - echo "| $language | $EXEC_STATUS | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE" - else - echo "| $language | Not Found or Not Executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE" - echo "Warning: $language script for $day not found or not executable" - fi + echo "| $language | Not Found or Not Executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE" + echo "Warning: $language script for $day not found or not executable" fi cd "$ROOT_DIR" } @@ -62,7 +44,8 @@ measure_execution_time() { # Loop through each DayXX folder for day_folder in $ROOT_DIR/Day*/; do day=$(basename "$day_folder") - echo "\n## $day" >> $ANALYTICS_FILE + echo "" >> $ANALYTICS_FILE + echo "## $day" >> $ANALYTICS_FILE echo "| Language | Status | Real Time | User Time | Sys Time |" >> $ANALYTICS_FILE echo "| --- | --- | --- | --- | --- |" >> $ANALYTICS_FILE diff --git a/package-lock.json b/package-lock.json index 15652f5..e975788 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "adventofcode2023", "version": "1.0.0", "license": "ISC", + "dependencies": { + "fs": "^0.0.1-security" + }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^6.13.2", "@typescript-eslint/parser": "^6.13.2", @@ -837,6 +840,11 @@ "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==", "dev": true }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", diff --git a/package.json b/package.json index c8e8a72..6c0ffbf 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,8 @@ "@typescript-eslint/eslint-plugin": "^6.13.2", "@typescript-eslint/parser": "^6.13.2", "eslint": "^8.55.0" + }, + "dependencies": { + "fs": "^0.0.1-security" } } diff --git a/tsconfig.json b/tsconfig.json index cafae5a..301024d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,6 @@ "esModuleInterop": true }, "include": [ - "Day**/{js,ts}/*.ts" + "Day**/ts/*.ts" ] } \ No newline at end of file