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): add prefer-standalone rule for checking all components, directives and pipes #1627
feat(eslint-plugin): add prefer-standalone rule for checking all components, directives and pipes #1627
Conversation
05f3885
to
57196ce
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 57196ce. 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 6 targetsSent with 💌 from NxCloud. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1627 +/- ##
==========================================
+ Coverage 89.56% 89.59% +0.02%
==========================================
Files 171 173 +2
Lines 3202 3229 +27
Branches 544 548 +4
==========================================
+ Hits 2868 2893 +25
- Misses 198 199 +1
- Partials 136 137 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @csvn I'm sorry for the delay in getting back to you on this one.
I think what might be best overall here is to create a new rule: prefer-standalone
which applies checks for all the things (as really people should either be doing all or nothing I think).
At the same time we deprecate the prefer-standalone-component
rule and look to remove it in the next major for clarity
I think that's a good idea. I'll update this MR soon based on that feedback. |
57196ce
to
ee4ebf2
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit ee4ebf2. 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 targetsSent with 💌 from NxCloud. |
const standaloneRuleFactory = | ||
(type: DecoratorTypes) => (node: TSESTree.Decorator) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contents of this function is the same as for prefer-standalone-component, with the addition of turning it into a factory function and passing in the decorator type
for the messageID data property.
|
||
const messageId: MessageIds = 'preferStandalone'; | ||
|
||
export const valid = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The valid
& invalid
test cases here are the same as for prefer-standalone-component
+ new cases for @Pipe
and @Directive
(taken from prior commits).
@JamesHenry I think I've addressed your feedback now, and that this PR is ready for review. Sorry for it taking a while for me to get back to this one. |
Thanks so much @csvn! |
Adds new rules for checking
@Directive
and@Pipe
for beingstandalone
as a companion to@Component
being checked by the existing rule.An alternative would be to add options to the current
prefer-standalone-component
rule to allow checking pipes/directives too, but I was afraid it might be confusing with the naming of the existing rule to also apply to directives/pipes. Let me know if think it would be better to merge the code into a single rule (it would likely be less code duplication), or refactor common code into utility functions maybe.