Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [no-unnecessary-parameter-property-assignment] add new rule#8903
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@yeonjuan! 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 onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedApr 11, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site configuration. |
nx-cloudbot commentedApr 11, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
☁️ Nx Cloud ReportCI is running/has finished running commands for commitb2690e4. 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 1 targetSent with 💌 fromNxCloud. |
f10ba89
to95cbd19
CompareThere 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.
This is looking great! Sorry for the long review time on it. It looked more intimidating from the outside to me than it ended up being 😅. A testament to the nice clean code on the inside!
Because scope analysis tends to be tricky, I went with a little more scrutiny than average on granular code nitpicking.
packages/eslint-plugin/docs/rules/no-unnecessary-parameter-property-assignment.mdx OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/tests/rules/no-unnecessary-parameter-property-assignment.test.tsShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
@JoshuaKGoldberg Thank you for your review. I fixed it. |
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/src/rules/no-unnecessary-parameter-property-assignment.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/tests/rules/no-unnecessary-parameter-property-assignment.test.tsShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
packages/eslint-plugin/tests/rules/no-unnecessary-parameter-property-assignment.test.tsShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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.
More test cases I have in mind:
this.foo = this.foo
setTimeout(() => this.foo = foo, 0)
declareconstkey:'foo';classFoo{constructor(privatefoo:string){this[key]=foo;}}
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.
setTimeout(() => this.foo = foo, 0)
That's covered enough by the(() => {})()
IMO. This just generally needs to check a call expression.
bitwise/shifting operators`
I think we're fine with the existing set of operators. They're similar enough in the AST that we don't need to be exhaustive.
declare const key: 'foo'
Covered bydeclare const name: string
IMO
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.
This looks lovely, thanks! 🧹
I only have small nitpicks left - happy to apply these before our Monday release.
</TabItem> | ||
</Tabs> | ||
{/* Intentionally Omitted: When Not To Use It */} |
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.
[Docs] To mention: if you don't use parameter properties, you can ignore this rule.
> | ||
> See **https://typescript-eslint.io/rules/no-unnecessary-parameter-property-assignment** for documentation. | ||
Parameter properties let you create and initialize a member in one place. |
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.
[Docs] This explanation is pretty sparse. We've been trying to flesh out our docs to be more useful. How about linking to the TypeScript docs?https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties
Parameterproperties let you createandinitialize a member in one place. | |
[TypeScript's parameterproperties](https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties) allow creatingandinitializing a member in one place. |
type MessageIds = 'unnecessaryAssign'; | ||
const UNNECESSARY_OPERATORS = new Set(['=', '&&=', '||=', '??=']); | ||
export default createRule<[], MessageIds>({ |
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.
[Style] No need to explicitly declare those type arguments ✨
typeMessageIds='unnecessaryAssign'; | |
constUNNECESSARY_OPERATORS=newSet(['=','&&=','||=','??=']); | |
exportdefaultcreateRule<[],MessageIds>({ | |
constUNNECESSARY_OPERATORS=newSet(['=','&&=','||=','??=']); | |
exportdefaultcreateRule({ |
docs: { | ||
description: | ||
'Disallow unnecessary assignment of constructor property parameter', | ||
requiresTypeChecking: false, |
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.
[Style] TIL three existing rules declare this explicitly ... but they don't need to:
requiresTypeChecking: false, |
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.
setTimeout(() => this.foo = foo, 0)
That's covered enough by the(() => {})()
IMO. This just generally needs to check a call expression.
bitwise/shifting operators`
I think we're fine with the existing set of operators. They're similar enough in the AST that we don't need to be exhaustive.
declare const key: 'foo'
Covered bydeclare const name: string
IMO
@JoshuaKGoldberg Thanks! I fixed!d22cb8b |
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.
🚀 thanks!
451e738
intotypescript-eslint:mainUh oh!
There was an error while loading.Please reload this page.
description: | ||
'Disallow unnecessary assignment of constructor property parameter', | ||
}, | ||
fixable: 'code', |
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.
Is this true? I'm not able to get it to fix my code, and I don't see where a fixer is passed tocontext.report
.
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.
Aha! You're right - this was an oversight.eslint/eslint#18008 would have caught it.
Are you up for filing an issue and/or sending a PR@dasa? It'd be a great contribution 😁
…remove `fixable` from `meta` (#9527)chore: remove `fixable` from `meta`No fixer is actually present.Ref:#8903 (comment)
Uh oh!
There was an error while loading.Please reload this page.
PR Checklist
Overview