Achieve quality code through modern tools and automation
Note: All of these practices also apply to pair and mob programming, code reviews & pull requests. Try to get all of the steps below working before you submit a pull request and your fellow developers will be very grateful.
Don't think of automation as just 'tests and testing'.. Automation in this context means also getting feedback from tools and technologies that can help.
Four key methods for getting that 'over your shoulder feedback' for Javascript, when you don't have a pair/mob are shown below. I also use them somewhat in order, e.g. linting (for errors at least) must pass before tests even run, etc.
- 'use strict'; Automatically gives helpful advice.
- Linting. With strong rules. This alone will give you constant feedback about poor practices.
- Tests. Lets never forget them. They provide constant feedback and advice.
- Code Coverage. Let these tools keep you honest and aim for 100% coverage at all times.
A fifth approach is to use a 'prettier' but personally the js one doesn't work for me (long discussion avoided). It might work for you however. That's OK too.
Sometimes I forget to add linting for a piece of code I am working on. And then I add it. Wow. I am usually amazed and humbled at all the things I cannot remember to do right. And each time I learn a little more about doing it right in the beginning next time :) Today for example, code coverage showed that a default parameter was untested and when I actually added a test the functionality turned out to be broken! Which I fixed. Thank you code coverage!
My linting rules as an example. I've been helped by most at one time or another.
rules:
indent:
- error
- 2
max-len:
- warn
- code: 120
no-dupe-else-if: error
no-dupe-keys: error
no-duplicate-case: error
no-unreachable: error
prefer-const: error
eqeqeq: error
semi: error
no-var: error
no-fallthrough: error
no-new: error
no-redeclare: error
vars-on-top: error
default-param-last: error
no-mixed-spaces-and-tabs: error
no-tabs: error
no-trailing-spaces: error
no-irregular-whitespace: error
no-unused-vars: error
no-nested-ternary: error
no-multiple-empty-lines: error
no-extra-boolean-cast: warn
no-extra-parens: warn
default-case: warn
no-else-return: warn
no-eq-null: warn
no-eval: warn
no-loop-func: warn
no-native-reassign: warn
no-param-reassign: warn
no-self-compare: warn
accessor-pairs: warn
block-scoped-var: warn
no-throw-literal: warn
prefer-regex-literals: warn
camelcase: warn
no-useless-rename: warn
prefer-rest-params: warn
prefer-template: warn
plugins:
- "mocha"