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: Detect potential undefined property #8895

Closed
1 of 4 tasks
erfanio opened this issue Jul 7, 2017 · 2 comments
Closed
1 of 4 tasks

New Rule: Detect potential undefined property #8895

erfanio opened this issue Jul 7, 2017 · 2 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon

Comments

@erfanio
Copy link

erfanio commented Jul 7, 2017

Please describe what the rule should do:
Detect if an undefined object property is being used. This might not always be able to verify the structure of the object, but it would be invaluable to detect problems down the road before they bubble up (this is especially annoying since javascript silently fails and just returns an undefined)

What category of rule is this?

  • Enforces code style
  • Warns about a potential error
  • Suggests an alternate way of doing something
  • Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

const foo = {
  bar: 'bar',
  hi: 'hi'
};
console.log(foo.baz); // Potential problem!
import foo from './foo';
console.log(foo.baz); // Not sure
const foo = {
  bar: 'bar',
  hi: 'hi'
};
console.log(foo.bar); // No problem

Why should this rule be included in ESLint (instead of a plugin)?
This would be useful for all developers. Everyone uses objects, but most importantly it would be valuable in places where you define a bunch of constants in an object (to be easily importable in other parts of the program).
Some people have encountered this issue and fixed it in their own community but easier detection would be super valuable. (for example in redux)

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jul 7, 2017
@erfanio
Copy link
Author

erfanio commented Jul 7, 2017

After writing this I realised that this probably too much to ask from a linter and would be the job of a type checking system.
Feel free to close this issue

@nzakas
Copy link
Member

nzakas commented Jul 7, 2017

Yeah, while we might be able to hack something together that kind of works, it's a lot harder than it looks. You really do need a type system to get the functionality you want.

@nzakas nzakas closed this as completed Jul 7, 2017
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

3 participants