Is it possible to catch typos like in switch case example statement below?
Preferred way would be that eslinter report an warning/error.
Currently adding toString()
to const
can be used to raise an TypeError
in runtime if undefined.
actionTypes.js
export const UPDATE_REQUEST = 'UPDATE_REQUEST';
reducer.js
import * as types from '../constants/actionTypes';
export default function pouchdbReducer(state = {}, action) {
switch (action.type) {
case types.UPDDATE_REQUEST:
// there is a typo above and it evaluates to `undefined`
// this code would never be reached - how to make it an error
return Object.assign({}, state, {updated: true});
default:
return state;
}
}
UPDATE:
As @nikc.org answered eslint-plugin-import with namespace option can be used for linting such bugs.
Here is small repository with configuration and demo:
https://github.com/bmihelac/test-js-import-undefined/tree/eslint-plugin-import
Relevant part of eslint config is:
"plugins": ["import"],
"rules": {
"import/namespace": [2],
Disclaimer, I'm the autor of tern-lint.
I suggest you that you use tern-lint which is able to report errors like "Unknown property".
You can use this linter with command or with an editor which supports it (Emacs, Atom, CodeMirror or Eclipse). Here a screenshot with Eclipse tern.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With