Skip to content

feat(eslint-plugin): [require-localize-metadata] add requireCustomId option #2430

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

Merged

Conversation

igord
Copy link
Contributor

@igord igord commented May 16, 2025

Similar to #2186, this PR adds one new rule requireCustomId that can be enabled:

  • by setting its value to true or
  • by setting it's value to a string representing regular expression for custom_id validation

It also refactors $localize metadata parsing to be closer to the way that @angular/localize does it

@igord igord changed the title Feature/refactor localize validation feature: refactor localize validation May 16, 2025
@igord igord changed the title feature: refactor localize validation feat: refactor localize validation May 16, 2025
@igord igord changed the title feat: refactor localize validation feat: requireCustomId rule for $localize May 16, 2025
tomas_backbase and others added 3 commits May 21, 2025 09:46
…dation

Added two more options to report errors if:
- Custom ID is not present
- Custom ID is present but it doesn't follow the allowed pattern
- Default value is not provided

Change in details:
- Added new configuration options and error messages for reporting.
- Create and use a `validate` function that receives the input string and a type to validate
optionally it can receive a pattern to validate custom id.
- The core of the `validate` function is a regular expression with named group, I have followed
how Angular manages metadata when using `$localize`
- Added new valid and invalid tests cases to cover the changes.

New config after changes:
- Added `requireCustomId` - `boolean` - default is `false`
- Added `requireDefaultValue` - `boolean` - default is `false`
- Added `boundTextAllowedPattern` - `string` - No default value. It expects to get a string that
can be converted to regular expression to test custom id. I have used the same name that already
exists in `@angular-eslint/template-parser`.
@igord igord force-pushed the feature/refactor-localize-validation branch from 163679a to a1dce40 Compare May 21, 2025 07:53
Copy link

nx-cloud bot commented May 24, 2025

View your CI Pipeline Execution ↗ for commit acb1795.

Command Status Duration Result
nx run-many -t e2e-suite --parallel 1 ✅ Succeeded 32s View ↗
nx run-many -t test --codeCoverage ✅ Succeeded 11s View ↗
nx run-many -t build,typecheck,check-rule-docs,... ✅ Succeeded 1m 7s View ↗
nx-cloud record -- pnpm nx sync:check ✅ Succeeded 2s View ↗
nx-cloud record -- pnpm format-check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2025-06-02 08:06:38 UTC

@JamesHenry JamesHenry changed the title feat: requireCustomId rule for $localize feat(eslint-plugin): [i18n] add requireCustomId option for $localize May 24, 2025
@JamesHenry JamesHenry changed the title feat(eslint-plugin): [i18n] add requireCustomId option for $localize feat(eslint-plugin): [require-localize-metadata] add requireCustomId option May 24, 2025
@igord igord force-pushed the feature/refactor-localize-validation branch from 2ca088b to da06715 Compare May 26, 2025 07:52
@igord igord force-pushed the feature/refactor-localize-validation branch from da06715 to e570d0f Compare May 26, 2025 08:32
@JamesHenry
Copy link
Member

@tcorral how do you feel about this approach as an alternative?

@JamesHenry
Copy link
Member

@igord CI not passing yet

@tcorral
Copy link

tcorral commented May 31, 2025

@tcorral how do you feel about this approach as an alternative?

@JamesHenry It looks good to me.

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Please run the CI commands locally before pushing, there are still multiple failures

@igord igord force-pushed the feature/refactor-localize-validation branch 3 times, most recently from ee9f8b9 to a1dce40 Compare June 1, 2025 15:31
Copy link

codecov bot commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.86%. Comparing base (74a854c) to head (acb1795).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...lint-plugin/src/rules/require-localize-metadata.ts 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2430      +/-   ##
==========================================
+ Coverage   92.85%   92.86%   +0.01%     
==========================================
  Files         200      200              
  Lines        4169     4203      +34     
  Branches      973      984      +11     
==========================================
+ Hits         3871     3903      +32     
- Misses        229      231       +2     
  Partials       69       69              
Flag Coverage Δ
unittest 92.86% <93.33%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...gin/tests/rules/require-localize-metadata/cases.ts 100.00% <100.00%> (ø)
...lint-plugin/src/rules/require-localize-metadata.ts 95.34% <93.10%> (-4.66%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JamesHenry JamesHenry merged commit 9750e38 into angular-eslint:main Jun 2, 2025
10 of 11 checks passed
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.

3 participants