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.

Related articles

How to write a simple, generic Result type to hold a value or Error.

2018
TypeScript

Beyond allowing the await keyword to be used within them, JavaScript’s async functions have their own useful aspects. As an alternative to Promise.resolve() and Promise.reject(), consider using async functions to cleanly wrap return values in Promises for convenient mocks in your test suite and to ensure consistent return types.

2018
JavaScript
TypeScript

How to integrate build-time or server-side syntax highlighting for markdown code fences with two libraries: markdown-it and Highlights (Atom’s syntax highlighting engine).

2017
Node.js
JavaScript
Performance