micromata / Baumeister

Unmaintained – :construction_worker: The aim of this project is to help you to build your things. From Bootstrap themes over static websites to single page applications.
MIT License
171 stars 37 forks source link

Configure ESLint rule no-undef with `{ "typeof": true }` #220

Closed mischah closed 6 years ago

mischah commented 6 years ago

Checking the existence of variables when using typeof comparisons helps to prevent bugs caused by small typos which are hard to spot otherwise.

Example:

get(localPath, defaultValue = null) {
  if (typeof(localpath) === 'undefined' || localPath === null || localPath === '' ) {
    return this.localFoo;
  }
} 

Try to spot the typo in one of the localPath references.

See: ESLint docs of this rule.

Config of this rule should be added here: https://github.com/micromata/Baumeister/blob/master/.eslintrc.json

nicolaisueper commented 6 years ago

Should a finding result in a warning or an error?

mischah commented 6 years ago

Error. And merry Christmas btw πŸŽ„

nicolaisueper commented 6 years ago

πŸŽ„πŸŽ… I totally forgot that it was Christmas at that moment. I hope you had a nice evening with your family.

mischah commented 6 years ago

Sorry, for the confusion. It’s already checking for undeclared variables in typeof comparisons thanks to eslint-config-xo.

See: https://github.com/sindresorhus/eslint-config-xo/blob/3f8179657736c4c078759416509ca9698e5321e6/index.js#L123-L125