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

prefer-early-return doesn't work when there is a variable #314

Open
2 tasks done
BenjaminVanRyseghem opened this issue Dec 21, 2021 · 1 comment · May be fixed by #412
Open
2 tasks done

prefer-early-return doesn't work when there is a variable #314

BenjaminVanRyseghem opened this issue Dec 21, 2021 · 1 comment · May be fixed by #412

Comments

@BenjaminVanRyseghem
Copy link

BenjaminVanRyseghem commented Dec 21, 2021

Overview

When extracting the if condition into a variable, the rule is suddenly satisfied.

Not sure if it's a bug or not, but this feel like it could be at least improved (yet I don't know if it's really feasible)

Examples:

The following is considered warning

	foo() {
		if (a) {
			b();
			c();
		}
	}

yet, the following is not

	foo() {
        var bar = a;
		if (bar) {
			b();
			c();
		}
	}

Checklist

  • Please delete the labels section before submitting your issue
  • I have described this issue in a way that is actionable (if possible)
@WesleyYue
Copy link

This also doesn't work:

export function foo1(a: string) {
  if (a) {
    console.log(a);
  }
}

miluoshi added a commit to miluoshi/web-configs that referenced this issue Feb 8, 2024
…s the last one in function body

Sometimes we assign a conditions used in "if" test to a variable before "if" statement. In such case it's not the only statement in the block, but it should be detected anyway.

closes Shopify#314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants