Rule proposal: `prefer-immediate-return`
See original GitHub issueIn my opinion it’s never desirable to assign a value to a variable, only to be returned immediately. I believe this is often the leftover result of debugging.
In other words, if a value is declared, and returned immediately in the next statement, the two should be merged, removing the useless variable.
Fail
// A
function foo() {
const result = bar();
return result;
}
// B
function foo() {
let result;
return result;
}
Pass
function foo() {
const result = bar();
// Anything in between is allowed.
console.log(result);
return result;
}
function foo() {
let result;
result = bar();
return result;
}
// Autofix result for A
function foo() {
return bar();
}
// Autofix result for B
function foo() {
return;
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:17 (3 by maintainers)
Top Results From Across the Web
SEC Adopts Amendments to Modernize Shareholder Proposal ...
The Securities and Exchange Commission today voted to adopt amendments to modernize its shareholder proposal rule, which governs the process ...
Read more >Why Some Evaluators Prefer Written Proposals | AiDA
They want to take their 50 or 100 pages or more of text to their corners of the source selection room and read...
Read more >Part 15 - Contracting by Negotiation | Acquisition.GOV
Extremely bulky proposals must only be returned at the offeror's ... the acquisition is not based on prices set by law or regulation; ......
Read more >A Guide to the Rulemaking Process - Federal Register
What are interim final rules & direct final rules? ... Following the preamble, the agency usually publishes the regulatory text of the proposal...
Read more >Summary of the SEC's Re-Proposal on the Use of Derivatives ...
The Proposal also includes new rules under the Securities Exchange Act of 1934 (the “Exchange Act”) and Investment Advisers Act of 1940 (the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This rule would also play nice with
no-return-await
. Currently an intermediate variable could be used to circumvent this rule.Becomes (because of
prefer-immediate-return
):Which then becomes (because of
no-return-await
):@fisker Why not a fan? It seems reasonable. When would that code be preferable?