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(eslint-plugin-template): fix control flow syntax with i18n rule #1656

Merged

Conversation

mattlewis92
Copy link
Contributor

@mattlewis92 mattlewis92 commented Dec 1, 2023

Adds support for control flow block syntax inside the i18n rule. Currently using elements inside control flow blocks will result in a lint error, even if there is a parent element that has the i18n attribute.

Fixes #1640

@@ -49,10 +49,11 @@ const KEYS: VisitorKeys = {
PropertyRead: ['receiver'],
Template: ['templateAttrs', 'children', 'inputs'],
BindingPipe: ['exp'],
DeferredBlock: ['children'],
DeferredBlock: ['children', 'placeholder', 'loading', 'error'],
Copy link
Contributor Author

@mattlewis92 mattlewis92 Dec 1, 2023

Choose a reason for hiding this comment

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

Without this angular-eslint won't parse elements within @placeholder, @loading or @error nodes inside of @defer blocks

DeferredBlockLoading: ['children'],
DeferredBlockError: ['children'],
DeferredBlockPlaceholder: ['children'],
ForLoopBlock: ['children', 'empty'],
Copy link
Contributor Author

@mattlewis92 mattlewis92 Dec 1, 2023

Choose a reason for hiding this comment

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

Without this angular-eslint won't parse elements inside of @empty nodes inside of @for blocks

Copy link

nx-cloud bot commented Dec 1, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit ee3ba44. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


⌛ The following targets are in progress

✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

@@ -99,6 +100,9 @@ function preprocessNode(node: Node) {

for (i = 0; i < keys.length; ++i) {
const child = node[keys[i]];
if (child == null) {
Copy link
Contributor Author

@mattlewis92 mattlewis92 Dec 1, 2023

Choose a reason for hiding this comment

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

Without this defer block parsing fails with:

● parseForESLint() › @defer › should support the different variants of @defer

    TypeError: Cannot read properties of null (reading 'type')

      105 |     }
      106 |     const isArr = Array.isArray(child);
    > 107 |     if (child.type !== undefined) {
          |               ^
      108 |       // Angular sometimes uses a prop called type already
      109 |       child.__originalType = child.type;
      110 |     }

      at preprocessNode (src/index.ts:107:15)
      at preprocessNode (src/index.ts:129:11)
      at parseForESLint (src/index.ts:272:3)
      at Object.<anonymous> (tests/index.test.ts:559:23)

Maybe I got something wrong in the visitor keys? But with this check everything seems to work ok so maybe it's the correct thing to do?

Copy link

codecov bot commented Dec 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5170f77) 89.44% compared to head (5da26b3) 89.50%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1656      +/-   ##
==========================================
+ Coverage   89.44%   89.50%   +0.05%     
==========================================
  Files         169      169              
  Lines        3175     3183       +8     
  Branches      540      542       +2     
==========================================
+ Hits         2840     2849       +9     
  Misses        198      198              
+ Partials      137      136       -1     
Flag Coverage Δ
unittest 89.50% <100.00%> (+0.05%) ⬆️

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

Files Coverage Δ
packages/eslint-plugin-template/src/rules/i18n.ts 92.74% <100.00%> (+1.21%) ⬆️
...s/eslint-plugin-template/tests/rules/i18n/cases.ts 100.00% <ø> (ø)
packages/template-parser/src/index.ts 89.36% <100.00%> (+0.23%) ⬆️

Copy link

nx-cloud bot commented Jan 6, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5da26b3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@JamesHenry JamesHenry merged commit 5f1b1b0 into angular-eslint:main Jan 6, 2024
14 checks passed
@JamesHenry
Copy link
Member

Thanks @mattlewis92!

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.

[template/i18n] doesn't work with control flow syntax
2 participants