Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #62: minimize incorrect matches for javascript function #63

Merged
merged 1 commit into from
Nov 8, 2021

Conversation

farhan443
Copy link
Contributor

Address #47
Fix #62

Before

function\*?(\s+[$\w]+\s*\(.*\)|\s*\(.*\))

After

function\*?\s*([A-Za-z$_][\w$]*)?\s*[(][^:;()]*[)]\s*{

Replaced patterns:

  • Wildcard ( . )
  • Alternation ( | )
  • Escaped meta character ( \meta )

This regex enforces the following:

  • Function name can't start with a digit
  • Parameters can't contain parentheses, colon and semicolon
  • There must be an opening curly bracket after the closing parentheses

Known remaining issues:

  • Doesn't match if the function name uses valid characters that are outside standard ASCII, e.g., accented letters, emoji, kanji, etc
  • Parameter's name is still too permissive, currently it only disallows 4 characters ((, ), :, ;)

@codecov
Copy link

codecov bot commented Nov 7, 2021

Codecov Report

Merging #63 (055387f) into master (009389b) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #63   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          947       947           
  Branches        43        43           
=========================================
  Hits           947       947           
Impacted Files Coverage Δ
src/languages/javascript.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 009389b...055387f. Read the comment docs.

@aldy505 aldy505 merged commit cae375d into teknologi-umum:master Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JavaScript regex matches function name that starts with a digit
2 participants