Tools for JavaScript standards

Consider using a couple lightweight tools to simplify the process of sharing and enforcing essential JavaScript standards across a project.

Automated linting

Linting is a form of static analysis to detect incorrect or potentially harmful code. JavaScript, as a dynamic language with some loose syntax possibilities, benefits especially well from linting. It can help catch errors on the spot or enforce guidelines about dangerous features.

The following tools provide various options to report on code based on slightly different philosophies. They can be run as part of an automated build step, as an editor plugin, or both.

  • ESLint is the current leader in configurable linting for JavaScript.
  • TSLint for TypeScript.
  • JSHint was a common choice prior to ESLint.

Shared editor configuration

Tabs or spaces? Any time a group of developers starts a conversation about file formatting standards, there’s bound to be disagreement.

A little tool called EditorConfig can be committed to the root of a project and used to share a few key stylistic choices around indentation, line ending, and character encoding. Plugins for a variety of IDEs and text editors will automatically pick up and enforce these configurations within the scope of the project.

JavaScript developers all come from different coding backgrounds, use different editors, and configure them with different defaults. It’s the universal language of the web, so it takes effort to keep everyone in sync — even for these simple choices. If a project specifies its standards with EditorConfig, I know I’ll make an effort to abide by them, and my editor will help.