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

infra(unicorn): better-regex #2487

Draft
wants to merge 10 commits into
base: next
Choose a base branch
from
Draft

infra(unicorn): better-regex #2487

wants to merge 10 commits into from

Conversation

ST-DDT
Copy link
Member

@ST-DDT ST-DDT commented Oct 20, 2023

@ST-DDT ST-DDT added p: 1-normal Nothing urgent c: infra Changes to our infrastructure or project setup labels Oct 20, 2023
@ST-DDT ST-DDT added this to the vAnytime milestone Oct 20, 2023
@ST-DDT ST-DDT requested review from a team October 20, 2023 22:04
@ST-DDT ST-DDT self-assigned this Oct 20, 2023
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fa26a44) 99.58% compared to head (b0a7350) 99.58%.
Report is 108 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2487      +/-   ##
==========================================
- Coverage   99.58%   99.58%   -0.01%     
==========================================
  Files        2787     2787              
  Lines      249376   249377       +1     
  Branches     1084     1084              
==========================================
- Hits       248333   248330       -3     
- Misses       1015     1019       +4     
  Partials       28       28              
Files Coverage Δ
src/modules/finance/iban.ts 100.00% <100.00%> (ø)
src/modules/git/index.ts 100.00% <100.00%> (ø)
src/modules/helpers/index.ts 98.98% <100.00%> (ø)
src/modules/image/providers/unsplash.ts 100.00% <100.00%> (ø)
src/modules/internet/index.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@@ -297,7 +297,7 @@ describe('internet', () => {
const [prefix, suffix] = email.split('@');

expect(prefix).toMatch(
/^Mike((\d{1,2})|([.!#$%&'*+-/=?^_`{|}~]Smith\d{1,2})|([.!#$%&'*+-/=?^_`{|}~]Smith))/
/^Mike((\d{1,2})|([!#$%&'*+-/=?^_`{|}~]Smith\d{1,2})|([!#$%&'*+-/=?^_`{|}~]Smith))/
Copy link
Member Author

Choose a reason for hiding this comment

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

For those of you that wonder like me where the . went:

+-/ === + - / === +, -, ., /

Copy link
Contributor

Choose a reason for hiding this comment

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

that is SUPER confusing. A human reading this would never think that

Copy link
Member

Choose a reason for hiding this comment

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

TBH, this regex pattern in general is super confusing. I just looked at it and noped out immediately.

@@ -98,21 +98,21 @@ describe('color', () => {
describe(`rgb({ format: 'css' })`, () => {
it('should return a random rgb color in css format', () => {
const color = faker.color.rgb({ format: 'css' });
expect(color).match(/^(rgb\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}\))$/);
expect(color).match(/^rgb\((?:\d{1,3}, ){2}\d{1,3}\)$/);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems harder to read than the original

Copy link
Member

Choose a reason for hiding this comment

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

That means that the regex in general is too complex for that use case IMO. Splitting this one statement into multiple expect statements would be welcome:

const color = faker.color.rgb({ format: 'css' });
expect(color.startsWith('rgb')).toBe(true);
expect(color).toContain('(');
expect(color.endsWith(')')).toBe(true);

const values = color.substring(4, color.length - 1).split(',');
expect(values).toHaveLength(3);
for(const value of values) {
  const numeric = Number.parseInt(value, 10);
  expect(numeric).not.toBe(NaN);
  expect(numeric).toBeGreaterThanOrEqual(0);
  expect(numeric).toBeLessThanOrEqual(255);
}

});
});

describe(`rgb({ format: 'binary' })`, () => {
it('should return a random rgb color in binary format', () => {
const color = faker.color.rgb({ format: 'binary' });
expect(color).match(/^([01]{8} [01]{8} [01]{8})$/);
expect(color).match(/^(?:[01]{8} ){2}[01]{8}$/);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems harder to read than the original

Copy link
Contributor

@matthewmayer matthewmayer left a comment

Choose a reason for hiding this comment

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

In general these are improvements but sometimes it seems to be harder to read.

@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Oct 21, 2023
@ST-DDT ST-DDT marked this pull request as draft October 22, 2023 21:53
@ST-DDT ST-DDT added the needs rebase There is a merge conflict label Nov 13, 2023
@ST-DDT
Copy link
Member Author

ST-DDT commented Feb 15, 2024

Team Decision

  • We will wait until after deprecation removals
  • We will continue with the rule in smaller chunks.
  • If regex patterns are too complex we should consider adding a comment what it does instead of chopping it in smaller pieces.

@ST-DDT ST-DDT added s: on hold Blocked by something or frozen to avoid conflicts and removed s: needs decision Needs team/maintainer decision labels Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: infra Changes to our infrastructure or project setup needs rebase There is a merge conflict p: 1-normal Nothing urgent s: on hold Blocked by something or frozen to avoid conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants