-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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): [explicit-member-accessibility] fix parameter properties bugs #912
fix(eslint-plugin): [explicit-member-accessibility] fix parameter properties bugs #912
Conversation
Thanks for the PR, @ankeetmaini! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint |
This fixes most of the cases, there's just one gotcha, that parameter prop check will be skipped if |
Codecov Report
@@ Coverage Diff @@
## master #912 +/- ##
==========================================
+ Coverage 94.05% 94.06% +<.01%
==========================================
Files 113 113
Lines 4931 4937 +6
Branches 1376 1378 +2
==========================================
+ Hits 4638 4644 +6
Misses 166 166
Partials 127 127
|
I am sorry, this is not a breaking change, as it doesn't change the existing config. |
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.
two comments, otherwise LGTM.
Thanks for taking the time to do this, and putting up with the churn!
packages/eslint-plugin/src/rules/explicit-member-accessibility.ts
Outdated
Show resolved
Hide resolved
break; | ||
} | ||
case 'no-public': { | ||
if (node.accessibility === 'public') { |
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.
I believe that this should also check for readonly
.
public foo
is valid (otherwise it's not a parameter property), but public readonly foo
is not
if (node.accessibility === 'public') { | |
if (node.accessibility === 'public' && node.readonly) { |
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.
I checked public readonly foo
in ASTExplorer using @typescript-eslint/parser, it showed that it is a valid AST.
Also if I were to add that check, if parameterProperties='no-public'
, then public foo: string
will pass as readonly is missing but still the access modifier is public.
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.
For explicit
:
public foo
and public readonly foo
are both considered valid (obviously!)
For no-public
:
public foo
is considered valid, because without public
, it's not a parameter prop.
public readonly foo
is considered invalid, because you can remove the accessibility modifier, and it's still a parameter property: readonly foo
.
We should probably document this in the readme so that it's a bit clearer, as I don't think that this is entirely intuitive.
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.
I've incorporated these changes, thanks a lot for putting these down. HAve added in the readme too :)
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.
LGTM! Thanks for doing this.
Fixes #617
Fixes #857