sindresorhus/eslint-plugin-unicorn

Rule proposal: Forbid reassign top level variable in functions

Closed

#1,092 opened on Jan 30, 2021

 (6 comments) (1 reaction) (0 assignees)JavaScript (468 forks)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

It's dangerous, and maybe get unexpected result when refactoring. In following example, if we change foo to async, or inside foo somehow reenter foo, cache may got change.

Fail

let cache; 

function foo() {
	cache = {};
	// ...
}

export default foo;

Pass

function foo() {
	let cache;

	// ...
}

Contributor guide