From 7a5ac642b728956ab284702aaade8b98c095aed3 Mon Sep 17 00:00:00 2001 From: Anas Chakroun Date: Tue, 22 Oct 2024 14:26:14 +0200 Subject: [PATCH] fix(log-feature): improve detection of anonymous function assignments to variables --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- src/line-code-processing/js/index.ts | 2 +- .../function/named-function-declaration.test.ts | 4 ++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82f048a..fd29ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the "turbo-console-log" extension will be documented in this file. +## [2.10.6] + +### Fixed + +- Improved detection of anonymous functions assigned to variable declarations, especially in cases where type annotations or complex expressions were used. + ## [2.10.5] ### Fixed diff --git a/package-lock.json b/package-lock.json index bb3373a..d89f5b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "turbo-console-log", - "version": "2.10.4", + "version": "2.10.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "turbo-console-log", - "version": "2.10.4", + "version": "2.10.5", "license": "SEE LICENSE IN LICENSE.txt", "dependencies": { "lodash": "^4.17.21" diff --git a/package.json b/package.json index c9bfea9..39fde39 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "turbo-console-log", "displayName": "Turbo Console Log", "description": "Automating the process of writing meaningful log messages.", - "version": "2.10.5", + "version": "2.10.6", "publisher": "ChakrounAnas", "engines": { "vscode": "^1.50.0" diff --git a/src/line-code-processing/js/index.ts b/src/line-code-processing/js/index.ts index 5e3aa47..e608ac2 100644 --- a/src/line-code-processing/js/index.ts +++ b/src/line-code-processing/js/index.ts @@ -62,7 +62,7 @@ export class JSLineCodeProcessing implements LineCodeProcessing { /(const|let|var)(\s*)[a-zA-Z0-9]*\s*=(\s*)\(.*\)(\s*){/, ); const arrowFunctionAssignedToVariableRegex = new RegExp( - /(const|let|var)(\s*)[a-zA-Z0-9]*\s*=.*=>.*/, + /(const|let|var)\s+[a-zA-Z_$][a-zA-Z0-9_$]*\s*=\s*\([^)]*\s*(?::\s*[a-zA-Z_$][a-zA-Z0-9_$<>,\s]*)?\)\s*(?::\s*[a-zA-Z_$][a-zA-Z0-9_$<>,\s]*)?\s*=>\s*{/, ); return ( regularNamedFunctionRegex.test(locWithoutFunctionKeyword) || diff --git a/src/test/unit/js/loc-processing/function/named-function-declaration.test.ts b/src/test/unit/js/loc-processing/function/named-function-declaration.test.ts index da5ba1b..6794282 100644 --- a/src/test/unit/js/loc-processing/function/named-function-declaration.test.ts +++ b/src/test/unit/js/loc-processing/function/named-function-declaration.test.ts @@ -33,6 +33,10 @@ export default (): void => { ]; it('Should return true when LOC contains named function declaration', () => { namedFunctionsLOCs.forEach((namedFunctionLOC) => { + // console.log( + // '🚀 ~ namedFunctionsLOCs.forEach ~ namedFunctionLOC:', + // namedFunctionLOC, + // ); expect( helpers.jsLineCodeProcessing.doesContainsNamedFunctionDeclaration( namedFunctionLOC,