Skip to content

fix(eslint-plugin): handle output() and input() functions in various rules #2098

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
merged 5 commits into from
Nov 23, 2024

Conversation

reduckted
Copy link
Contributor

Fixes #2004

Rules affected:

  • no-output-native
  • no-output-on-prefix
  • no-output-rename
  • no-input-rename

This change makes no-output-native check properties that are initialized to the result of the output() function. This was achieved by changing the selector to also look for properties that are assigned the result of a call expression for an output function that contains an object expression with an alias property. The no-output-native rule itself did not need to change.

As mentioned by @5im0n in #2004 (comment), the no-output-on-prefix rule was also not checking properties that are initialized to the result of the output() function. Because it uses the same selector, that rule now also checks those properties.

The no-output-rename rule also wasn't checking for output() properties, and due to the changes to the selectors, it now does. The rule itself did have to change to account for the alias coming from a property in an object expression instead of just being the single parameter to the @Output() decorator.

The no-input-rename rule wasn't affected by the changes to the selectors for the rules mentioned above, but I thought it was a good idea to update it at the same time because the changes that needed to be made to the rule were almost identical to the changes made to no-output-rename - it just had to account for the alias property being on an object expression that is the second argument to input() instead of the first argument like it would be for output().

@reduckted reduckted changed the title fix(eslint-plugin) handle output() and input() functions in various rules fix(eslint-plugin): handle output() and input() functions in various rules Nov 18, 2024
Copy link

nx-cloud bot commented Nov 18, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 25e0fb0. 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.

export const INPUT_ALIAS = `:matches(PropertyDefinition, MethodDefinition[kind='set']) ${INPUT_DECORATOR} ${LITERAL_OR_TEMPLATE_ELEMENT}`;
export const INPUT_ALIAS = [
`:matches(PropertyDefinition, MethodDefinition[kind='set']) ${INPUT_DECORATOR} > CallExpression > Literal`,
`:matches(PropertyDefinition, MethodDefinition[kind='set']) ${INPUT_DECORATOR} > CallExpression > TemplateLiteral > TemplateElement`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ℹ️ I didn't use LITERAL_OR_TEMPLATE_ELEMENT here. Using that selector means the no-input-rename rule would need to check if the string that matched is the value of an alias property to avoid false positives. By using three different selectors, it guarantees that it matches to either @Output('foo') or @Output(`foo`) or @Output({ alias: 'foo' }), and won't match to something like @Output({ test: 'foo' }).

You'll see in the no-input-rename rule that I've been able to remove the two checks where it was looking for the parent property or object expression to determine if the matched literal was the value of an alias property.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

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

Project coverage is 91.05%. Comparing base (ba27de5) to head (25e0fb0).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...ackages/eslint-plugin/src/rules/no-input-rename.ts 92.85% 0 Missing and 1 partial ⚠️
...ckages/eslint-plugin/src/rules/no-output-rename.ts 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2098      +/-   ##
==========================================
+ Coverage   90.99%   91.05%   +0.06%     
==========================================
  Files         181      181              
  Lines        3475     3521      +46     
  Branches      580      587       +7     
==========================================
+ Hits         3162     3206      +44     
+ Misses        165      164       -1     
- Partials      148      151       +3     
Flag Coverage Δ
unittest 91.05% <96.42%> (+0.06%) ⬆️

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

Files with missing lines Coverage Δ
...eslint-plugin/tests/rules/no-input-rename/cases.ts 100.00% <100.00%> (ø)
...slint-plugin/tests/rules/no-output-native/cases.ts 100.00% <ø> (ø)
...nt-plugin/tests/rules/no-output-on-prefix/cases.ts 100.00% <ø> (ø)
...slint-plugin/tests/rules/no-output-rename/cases.ts 100.00% <100.00%> (ø)
...ackages/eslint-plugin/src/rules/no-input-rename.ts 89.85% <92.85%> (+0.46%) ⬆️
...ckages/eslint-plugin/src/rules/no-output-rename.ts 91.37% <92.85%> (-1.65%) ⬇️
---- 🚨 Try these New Features:

@JamesHenry JamesHenry mentioned this pull request Nov 21, 2024
14 tasks
@JamesHenry JamesHenry merged commit 431a402 into angular-eslint:main Nov 23, 2024
7 checks passed
@JamesHenry
Copy link
Member

Thanks so much!

@reduckted reduckted deleted the feature/2004 branch November 23, 2024 11:42
@JLa2r
Copy link

JLa2r commented Jan 31, 2025

I know this is old and closed, but can this be updated with an "allowPrefix" option like some other rules have?
Reason: I name my signals prefixed with a "$" character e.g. $value = input("");
but alias the input to "value" e.g. $value = input("", { alias: 'value'});
so the consuming components can bind to [value] instead of [$value].

My current workaround is to just disable this rule.

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.

no-output-native should handle new ouput() function
3 participants