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

New rule: Prefer short-circuiting assignment operators (TS 4+) #2263

Closed
glen-84 opened this issue Jun 28, 2020 · 6 comments
Closed

New rule: Prefer short-circuiting assignment operators (TS 4+) #2263

glen-84 opened this issue Jun 28, 2020 · 6 comments
Labels
enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@glen-84
Copy link
Contributor

glen-84 commented Jun 28, 2020

Info:

Bad:

opts.foo = opts.foo ?? 'bar'

Good:

opts.foo ??= 'bar'

(same for ||= and &&=)

Optional extras:

Bad:

if (!a) {
  a = 'foo';
}

Good:

a ||= 'foo';

Bad:

opts.baz ?? (opts.baz = 'qux');

Good:

opts.baz ??= 'qux';
@glen-84 glen-84 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jun 28, 2020
@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for maintainers to take a look labels Jun 29, 2020
@bradzacher
Copy link
Member

Will require #2260

@JoshuaKGoldberg
Copy link
Member

Looks like this one is unblocked - I'll take it on! 🙌

@JoshuaKGoldberg
Copy link
Member

Actually, on second thought, this really isn't a TypeScript-specific rule, as the operators are general JavaScript syntax. Should this be moved to ESLint core @bradzacher?

@bradzacher
Copy link
Member

Probably could do yeah. They have support for the new logical operators!

@glen-84
Copy link
Contributor Author

glen-84 commented Sep 11, 2020

I'll move this issue (probably on Sunday or Monday).

@glen-84
Copy link
Contributor Author

glen-84 commented Sep 15, 2020

Closing in favour of eslint/eslint#13689.

@glen-84 glen-84 closed this as completed Sep 15, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants