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(eslint-plugin-template): [self-closing-tags] add rule #1322

Merged
merged 5 commits into from
Jun 3, 2023

Conversation

aleesaan
Copy link
Contributor

Implements the feature proposed in this discussion.

Let me know If there's a better way to check that an element has no content, and thanks for the awesome plugin!

@nx-cloud
Copy link

nx-cloud bot commented Mar 10, 2023

☁️ Nx Cloud Report

Attention: This version of the Nx Cloud GitHub bot will cease to function on July 1st, 2023. An organization admin can update your integration here.

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

📂 See all runs for this branch


✅ Successfully ran 7 targets

Sent with 💌 from NxCloud.

@aleesaan aleesaan force-pushed the self-closing-tags branch 2 times, most recently from 3d1fada to 45b1d9b Compare March 15, 2023 16:05
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.

Thanks a lot for this @aleesaan! Please see the comments inline

Copy link
Member

Choose a reason for hiding this comment

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

Please use the existing getDomElements() utility that we have and do not introduce a new list for us to maintain separately.

You can have a look in https://github.com/angular-eslint/angular-eslint/blob/6abcc3ab0d3000d00ab668d2f6776e0f851b0a41/packages/eslint-plugin-template/src/rules/accessibility-role-has-required-aria.ts for precedent on how to select native elements (and here you want to do the inverse, and only select non-native)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for the feedback! I was in fact looking for this kind of suggestions 😅 I pushed the fixes, let me know how it looks.

const parserServices = getTemplateParserServices(context);

return {
Element$1({
Copy link
Member

Choose a reason for hiding this comment

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

Please see comment about applying the filter of non-native elements in the selector

(startSourceSpan.start.offset === endSourceSpan.start.offset &&
startSourceSpan.end.offset === endSourceSpan.end.offset);

if (isNative || !noContent || noCloseTag) {
Copy link
Member

Choose a reason for hiding this comment

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

We should exit early on isNative as soon as we know about it on line 40

@JamesHenry
Copy link
Member

Thanks a lot @aleesaan after that one final change and syncing up with the latest this is ready to merge!

@aleesaan
Copy link
Contributor Author

aleesaan commented Jun 1, 2023

Fixed the last things and rebased! Let me know if it's all looking good :)

@JamesHenry JamesHenry enabled auto-merge (squash) June 3, 2023 14:44
@codecov
Copy link

codecov bot commented Jun 3, 2023

Codecov Report

Merging #1322 (c39ce93) into main (e7c762a) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1322      +/-   ##
==========================================
+ Coverage   89.30%   89.39%   +0.09%     
==========================================
  Files         160      162       +2     
  Lines        2991     3018      +27     
  Branches      501      506       +5     
==========================================
+ Hits         2671     2698      +27     
  Misses        200      200              
  Partials      120      120              
Flag Coverage Δ
unittest 89.39% <100.00%> (+0.09%) ⬆️

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

Impacted Files Coverage Δ
packages/eslint-plugin-template/src/index.ts 69.23% <ø> (+0.60%) ⬆️
...gin-template/src/rules/prefer-self-closing-tags.ts 100.00% <100.00%> (ø)
...late/tests/rules/prefer-self-closing-tags/cases.ts 100.00% <100.00%> (ø)

@JamesHenry JamesHenry merged commit 6d26c59 into angular-eslint:main Jun 3, 2023
14 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.

None yet

3 participants