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

chore: improve regex usage #2108

Merged
merged 2 commits into from
May 1, 2023
Merged

chore: improve regex usage #2108

merged 2 commits into from
May 1, 2023

Conversation

Shinigami92
Copy link
Member

@Shinigami92 Shinigami92 commented Apr 28, 2023

extracted #2102

Changes the usage of regexp to always follow RegExp#method(string).
As a side effect this fixes some potential null value type issues currently hidden by our tsconfig.

@Shinigami92 Shinigami92 added the c: chore PR that doesn't affect the runtime behavior label Apr 28, 2023
@Shinigami92 Shinigami92 requested a review from a team as a code owner April 28, 2023 15:16
@Shinigami92 Shinigami92 self-assigned this Apr 28, 2023
@Shinigami92 Shinigami92 added the p: 1-normal Nothing urgent label Apr 28, 2023
@codecov
Copy link

codecov bot commented Apr 28, 2023

Codecov Report

Merging #2108 (a8fbfd1) into next (a8dc7e0) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head a8fbfd1 differs from pull request most recent head 1ff2ade. Consider uploading reports for the commit 1ff2ade to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2108      +/-   ##
==========================================
- Coverage   99.59%   99.59%   -0.01%     
==========================================
  Files        2567     2567              
  Lines      243394   243371      -23     
  Branches     1254     1252       -2     
==========================================
- Hits       242420   242396      -24     
- Misses        947      948       +1     
  Partials       27       27              
Impacted Files Coverage Δ
src/modules/finance/index.ts 100.00% <100.00%> (ø)
src/modules/helpers/index.ts 99.07% <100.00%> (ø)
src/modules/internet/index.ts 100.00% <100.00%> (ø)

... and 21 files with indirect coverage changes

Copy link
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

@Shinigami92 Shinigami92 requested a review from a team April 29, 2023 08:43
@Shinigami92
Copy link
Member Author

🤷

May I ask what the value of this reaction was intended?

If you want to understand why this PR, please just gentle ask for it

string.match(RegExp) bleeds to an token.index that can potentially undefined
where as RegExp.exec(string) does not
this PR is a preparation and extraction of #2102 and should be merged before we can work further with that other PR

beside that RegExp.test(string) just returns a boolean instead of Result|null, so the thrown away overhead is reduced

@ST-DDT
Copy link
Member

ST-DDT commented Apr 29, 2023

May I ask what the value of this reaction was intended?

The intention behind this comment was originally to point out that some of your PR descriptions - especially for those PRs that dont fix an obvious bug - tend to be on a the shorter side and omit the part containing the intend and reasoning.
This makes them harder to understand/more ambigouus than necessary same as the lonely smiley.

I had also hoped that during the talk about this change I had successfully conveijed how unsure I am regarding the two methods and their differences.

@matthewmayer
Copy link
Contributor

i think this could be split into two. Seems like you are doing two things...

  1. Replace str.match(regex) with regex.test(string) if you only need a boolean "it matches" or "it doesn't match" like inside an if-condition.

  2. Replace str.match(regex) with regex.exec(str) if you do need the return values - but i'm not sure of the reason for this change, as the output seems to be the same if there is no /g flag on the regex - an object if it matches, or null if it doesn't

@ST-DDT
Copy link
Member

ST-DDT commented Apr 29, 2023

i think this could be split into two.

I don't think this is necessary, as they are close enough.

2. but i'm not sure of the reason for this change, as the output seems to be the same if there is no /g flag on the regex

There is a type difference there that avoid an issue in combination with the PR mentioned above.
A better description would make this easier to detect.

@ST-DDT ST-DDT changed the title chore: improve regex chore: improve regex usage May 1, 2023
@ST-DDT ST-DDT enabled auto-merge (squash) May 1, 2023 09:15
@ST-DDT ST-DDT merged commit ec1ca12 into next May 1, 2023
@Shinigami92 Shinigami92 deleted the regex branch May 1, 2023 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: chore PR that doesn't affect the runtime behavior p: 1-normal Nothing urgent
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants