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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent-abbreviations: event_ is suffixed with underscore #667

Closed
felixfbecker opened this issue Apr 7, 2020 · 13 comments
Closed

prevent-abbreviations: event_ is suffixed with underscore #667

felixfbecker opened this issue Apr 7, 2020 · 13 comments

Comments

@felixfbecker
Copy link

Why is event_ suffixed with underscore? 馃

Please rename the variable `e`. Suggested names are: `error`, `event_`. A more descriptive name will do too.
@fisker
Copy link
Collaborator

fisker commented Apr 7, 2020

Can you check your code? I guess event is used somewhere. See #579

@fisker
Copy link
Collaborator

fisker commented Apr 30, 2020

This is expected, unless you didn't use event.

@fisker fisker closed this as completed Apr 30, 2020
@felixfbecker
Copy link
Author

felixfbecker commented May 27, 2020

I checked the code and there is no shadowed variable event anywhere in the scope. Here's an example where the rule complained:

https://github.com/sourcegraph/sourcegraph/blob/2b86b78820bf291c611bfea3493fcbab012d60bb/web/src/user/settings/accessTokens/UserSettingsCreateAccessTokenPage.tsx#L76

There is an eventLogger in scope, but not event

Could this be reopened?

@fisker
Copy link
Collaborator

fisker commented May 27, 2020

@fisker fisker reopened this May 27, 2020
@fisker
Copy link
Collaborator

fisker commented May 27, 2020

Actually, I thought about this before, do we really need check scope up?

@felixfbecker
Copy link
Author

Ah, that makes sense. Hmm.

Could the suffixing only be done if the same-name variable is actually used in the scope? If it's not used, it shouldn't be necessary to give it a different name

@felixfbecker
Copy link
Author

I.e. only suffix in a case like this:

let error
try {
  foo()
} catch (error_) {
  error = error_
}

but not in this case:

let error
try {
  foo()
} catch (error) {
  console.error(error)
}

@fisker
Copy link
Collaborator

fisker commented May 27, 2020

Yes, it could be done, but @bmish bring the no-shadow rule up today #749 (comment) .

I'm not sure what should we do

@felixfbecker
Copy link
Author

I don't know how ESLint works, but could the rule detect whether no-shadow is used? Alternatively, have an option so the user can allow shadowing specifically

@fisker
Copy link
Collaborator

fisker commented May 27, 2020

I think we don't read use configs in any other rule.

BTW: what's your opinion about child scopes?

try {

} catch (x) {
//       ^ we have a rule fix this to error, currently we are fixing to `error`, not `error_`, should we check the child scope?
	try {
	
	} catch (error) {
	
	}
}

@felixfbecker
Copy link
Author

Fine to fix to error, unless inside the second catch there is a reference to x (which there isn't).

@fisker
Copy link
Collaborator

fisker commented May 27, 2020

Yep, I prefer error too, but again, against no-shadow(with option all).

@fisker
Copy link
Collaborator

fisker commented May 27, 2020

Let's close this issue for now, we can discuss the avoidCapture logic later.

@fisker fisker closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants