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

feat(config): generate default config with readonly and as const #2542

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

matthieu-crouzet
Copy link
Contributor

Related issues

🐛 Fix #2530

@matthieu-crouzet matthieu-crouzet requested a review from a team as a code owner December 2, 2024 15:55
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 90.32258% with 3 lines in your changes missing coverage. Please review.

Project coverage is 71.87%. Comparing base (28ffcb9) to head (cea1241).
Report is 9 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...alization/schematics/add-localization-key/index.ts 50.00% 1 Missing and 1 partial ⚠️
...or/helpers/component/component-config.extractor.ts 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matthieu-crouzet matthieu-crouzet force-pushed the feat/configuration-as-const branch from c42ec3c to cea1241 Compare December 2, 2024 17:02
findFilesInTree,
} from '@o3r/schematics';

const regexp = /translations\s*:\s*(?:Readonly<)?([A-Z][\w]*)(?:>)?\s*=\s*({[^;]+})\s*(as\s*const)?\s*;/g;
Copy link
Contributor

Choose a reason for hiding this comment

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

To handle different linter rule guidelines it can be an easy fix to turn the ; non-mandatory :

Suggested change
const regexp = /translations\s*:\s*(?:Readonly<)?([A-Z][\w]*)(?:>)?\s*=\s*({[^;]+})\s*(as\s*const)?\s*;/g;
const regexp = /translations\s*:\s*(?:Readonly<)?([A-Z][\w]*)(?:>)?\s*=\s*({[^;]+})\s*(as\s*const)?\s*;?/g;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more difficult to detect the end of the object then
; is used before in the regexp for that ({[^;]+})

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I propose:

/translations\s*:\s*(?:Readonly<)?([A-Z][\w]*)(?:>)?\s*=\s*({(?:[^:]+:\s*(?:".*"|'.*'|\s*,\s*))*\s*})\s*(as\s*const)?\s*;?/g

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does not work for complex object like the one in this example
https://regex101.com/r/2HTPCa/1

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed but it is working for localisation, which is what you want to parse, don't you?
(And it does support ; within the translation key even if I am not sure we do support it farer in the extractor 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes my point was that I have the same issue (and same regexp, expect the starting point) for configuration

@matthieu-crouzet matthieu-crouzet added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit 18786c6 Dec 3, 2024
36 checks passed
@matthieu-crouzet matthieu-crouzet deleted the feat/configuration-as-const branch December 3, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Generate Localization and Configuration object with as const contrains
3 participants