Today I read about javascript code smells from http://elijahmanor.com/talks/js-smells (twitter @elijahmanor), it is really good, so summarize here.
1. Too complex
jshint maxstatements, maxdepth, maxcomplexity
jshint, eslint, jscomplexity, escomplex, jasmine
2. Copy & Paste
jsinspect, JSCPD
3. Use switch statement
Violates open/closed principle (OCP) - open for extension but closed for modification
Use Strategy design pattern
4. Magic strings
Object types, const, symbols
eslint-plugin-smells
eslint-disable
5. This abyss
that, self, me etc
Use alternatives: bind, 2nd parameter of forEach, ES6, functional programming
6. String Concat
Template strings, handlerbar, ES6
no-complex-string-concat
7. Inappropriate intimacy (tight coupled)
Dependency injection, or message broker (pub/sub)
eslint-plugin-backbone
eslint-plugin-react
http://bit.ly/js-smells
No comments:
Post a Comment